From ed951667ec610b8ad48a49a606b6b1c33c60914d Mon Sep 17 00:00:00 2001 From: smizrahi Date: Tue, 2 Jul 2024 11:12:54 +0200 Subject: [PATCH] feat(mail): Improve mail search (advanced search) --- UI/MailerUI/UIxMailListActions.m | 35 +++---------------- .../MailerUI/UIxMailFolderTemplate.wox | 4 +-- 2 files changed, 7 insertions(+), 32 deletions(-) diff --git a/UI/MailerUI/UIxMailListActions.m b/UI/MailerUI/UIxMailListActions.m index 29cac782d..ff077884a 100644 --- a/UI/MailerUI/UIxMailListActions.m +++ b/UI/MailerUI/UIxMailListActions.m @@ -531,8 +531,7 @@ searchString = [NSString stringWithFormat: @"(date >= (NSCalendarDate)\"%@\" AND date <= (NSCalendarDate)\"%@\")", dateFrom, dateTo]; } else if ([searchBy isEqualToString: @"attachment"]) { // Attachment - // Not possible with imap search, check in getUIDsInFolder method - // The attachments must be checked in headers + searchString = [NSString stringWithFormat: @"(text = 'attachment;') AND (text = 'filename')"]; } else if ([searchBy isEqualToString: @"favorite"]) { // Favorite flaggedOnly = YES; @@ -552,16 +551,15 @@ searchString = [NSString stringWithFormat: @"%@ OR", searchString]; } - searchString = [NSString stringWithFormat: @"%@ (subject doesContain: '%@' OR body doesContain: '%@')", - searchString, searchInput, searchInput]; + searchString = [NSString stringWithFormat: @"%@ (subject doesContain: '%@' OR body doesContain: '%@' OR text = 'filename=*%@*')", + searchString, searchInput, searchInput, searchInput]; j++; } searchString = [NSString stringWithFormat: @"%@)", searchString]; } else { - searchString = [NSString stringWithFormat: @"(subject doesContain: '%@' OR body doesContain: '%@')", - searchInput, searchInput]; + searchString = [NSString stringWithFormat: @"(subject doesContain: '%@' OR body doesContain: '%@' OR text = 'filename=*%@*')", + searchInput, searchInput, searchInput]; } - } else if ([searchBy isEqualToString: @"not_contains"]) { // Not contains searchInput = [searchInput stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"]; @@ -891,29 +889,6 @@ headers = [self getHeadersForUIDs: [a subarrayWithRange: r] inFolder: folder]; - // This part is used to filter attachements when searching - // There is no way to filter only attachments when using imap SEARCH - if (onlyAttachments) { - tmpHeaders = [NSMutableArray arrayWithArray: headers]; - tmpUids = [NSMutableArray arrayWithArray: uids]; - - for (i = ([tmpHeaders count] - 1); i > 0; i--) { - // Search for no attachment - if (0 == [[[tmpHeaders objectAtIndex: i] objectAtIndex: 1] intValue]) { - uid = [[tmpHeaders objectAtIndex: i] objectAtIndex: 10]; // Uid - [tmpHeaders removeObjectAtIndex: i]; - - for (j = ([tmpUids count] - 1); j >= 0; j--) { - if ([uid isEqual: [tmpUids objectAtIndex: j]]) { - [tmpUids removeObjectAtIndex: j]; // -1 for header - } - } - } - } - headers = [tmpHeaders copy]; - uids = [tmpUids copy]; - } - [data setObject: headers forKey: @"headers"]; } diff --git a/UI/Templates/MailerUI/UIxMailFolderTemplate.wox b/UI/Templates/MailerUI/UIxMailFolderTemplate.wox index 0101f8875..c66cd9e6b 100644 --- a/UI/Templates/MailerUI/UIxMailFolderTemplate.wox +++ b/UI/Templates/MailerUI/UIxMailFolderTemplate.wox @@ -512,13 +512,13 @@ - +