-
-
Notifications
You must be signed in to change notification settings - Fork 104
feat: protect the Date header #6877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
link2xt
wants to merge
1
commit into
main
Choose a base branch
from
link2xt/protect-date-header
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -581,52 +581,26 @@ impl Imap { | |
|
||
// Determine the target folder where the message should be moved to. | ||
// | ||
// If we have seen the message on the IMAP server before, do not move it. | ||
// We only move the messages from the INBOX folder. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and Spam folders. |
||
// This is required to avoid infinite MOVE loop on IMAP servers | ||
// that alias `DeltaChat` folder to other names. | ||
// For example, some Dovecot servers alias `DeltaChat` folder to `INBOX.DeltaChat`. | ||
// In this case Delta Chat configured with `DeltaChat` as the destination folder | ||
// would detect messages in the `INBOX.DeltaChat` folder | ||
// and try to move them to the `DeltaChat` folder. | ||
// Such move to the same folder results in the messages | ||
// getting a new UID, so the messages will be detected as new | ||
// In this case moving from `INBOX.DeltaChat` to `DeltaChat` | ||
// results in the messages getting a new UID, | ||
// so the messages will be detected as new | ||
// in the `INBOX.DeltaChat` folder again. | ||
let _target; | ||
let target = if let Some(message_id) = &message_id { | ||
let msg_info = | ||
message::rfc724_mid_exists_ex(context, message_id, "deleted=1").await?; | ||
let delete = if let Some((_, _, true)) = msg_info { | ||
let delete = if let Some((_, true)) = msg_info { | ||
info!(context, "Deleting locally deleted message {message_id}."); | ||
true | ||
} else if let Some((_, ts_sent_old, _)) = msg_info { | ||
let is_chat_msg = headers.get_header_value(HeaderDef::ChatVersion).is_some(); | ||
let ts_sent = headers | ||
.get_header_value(HeaderDef::Date) | ||
.and_then(|v| mailparse::dateparse(&v).ok()) | ||
.unwrap_or_default(); | ||
let is_dup = is_dup_msg(is_chat_msg, ts_sent, ts_sent_old); | ||
if is_dup { | ||
info!(context, "Deleting duplicate message {message_id}."); | ||
} | ||
is_dup | ||
} else { | ||
false | ||
}; | ||
if delete { | ||
&delete_target | ||
} else if context | ||
.sql | ||
.exists( | ||
"SELECT COUNT (*) FROM imap WHERE rfc724_mid=?", | ||
(message_id,), | ||
) | ||
.await? | ||
{ | ||
info!( | ||
context, | ||
"Not moving the message {} that we have seen before.", &message_id | ||
); | ||
folder | ||
} else { | ||
_target = target_folder(context, folder, folder_meaning, &headers).await?; | ||
&_target | ||
|
@@ -707,7 +681,6 @@ impl Imap { | |
.fetch_many_msgs( | ||
context, | ||
folder, | ||
uid_validity, | ||
uids_fetch_in_batch.split_off(0), | ||
&uid_message_ids, | ||
fetch_partially, | ||
|
@@ -1305,7 +1278,6 @@ impl Session { | |
&mut self, | ||
context: &Context, | ||
folder: &str, | ||
uidvalidity: u32, | ||
request_uids: Vec<u32>, | ||
uid_message_ids: &BTreeMap<u32, String>, | ||
fetch_partially: bool, | ||
|
@@ -1433,18 +1405,7 @@ impl Session { | |
context, | ||
"Passing message UID {} to receive_imf().", request_uid | ||
); | ||
match receive_imf_inner( | ||
context, | ||
folder, | ||
uidvalidity, | ||
request_uid, | ||
rfc724_mid, | ||
body, | ||
is_seen, | ||
partial, | ||
) | ||
.await | ||
{ | ||
match receive_imf_inner(context, rfc724_mid, body, is_seen, partial).await { | ||
Ok(received_msg) => { | ||
if let Some(m) = received_msg { | ||
received_msgs.push(m); | ||
|
@@ -1952,7 +1913,9 @@ pub async fn target_folder_cfg( | |
|
||
if folder_meaning == FolderMeaning::Spam { | ||
spam_target_folder_cfg(context, headers).await | ||
} else if needs_move_to_mvbox(context, headers).await? { | ||
} else if folder_meaning == FolderMeaning::Inbox | ||
&& needs_move_to_mvbox(context, headers).await? | ||
{ | ||
Ok(Some(Config::ConfiguredMvboxFolder)) | ||
} else { | ||
Ok(None) | ||
|
@@ -2121,7 +2084,9 @@ fn get_folder_meaning_by_name(folder_name: &str) -> FolderMeaning { | |
]; | ||
let lower = folder_name.to_lowercase(); | ||
|
||
if SENT_NAMES.iter().any(|s| s.to_lowercase() == lower) { | ||
if lower == "inbox" { | ||
FolderMeaning::Inbox | ||
} else if SENT_NAMES.iter().any(|s| s.to_lowercase() == lower) { | ||
FolderMeaning::Sent | ||
} else if SPAM_NAMES.iter().any(|s| s.to_lowercase() == lower) { | ||
FolderMeaning::Spam | ||
|
@@ -2280,15 +2245,6 @@ pub(crate) async fn prefetch_should_download( | |
Ok(should_download) | ||
} | ||
|
||
/// Returns whether a message is a duplicate (resent message). | ||
pub(crate) fn is_dup_msg(is_chat_msg: bool, ts_sent: i64, ts_sent_old: i64) -> bool { | ||
// If the existing message has timestamp_sent == 0, that means we don't know its actual sent | ||
// timestamp, so don't delete the new message. E.g. outgoing messages have zero timestamp_sent | ||
// because they are stored to the db before sending. Also consider as duplicates only messages | ||
// with greater timestamp to avoid deleting both messages in a multi-device setting. | ||
is_chat_msg && ts_sent_old != 0 && ts_sent > ts_sent_old | ||
} | ||
|
||
/// Marks messages in `msgs` table as seen, searching for them by UID. | ||
/// | ||
/// Returns updated chat ID if any message was marked as seen. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not looking at uidvalidity anymore? Moreover, it's still
SELECT
ed above