Reputation: 50707
I am able to fetch all messages using fetchMessagesByUIDOperationWithFolder:
, however, message.flags all return 0 when some messages are unread, most are read and some are starred.
MCOIMAPMessagesRequestKind requestKind = MCOIMAPMessagesRequestKindHeaders;
NSString *folder = @"INBOX";
MCOIndexSet *uids = [MCOIndexSet indexSetWithRange:MCORangeMake(1, UINT64_MAX)];
MCOIMAPFetchMessagesOperation *fetchOperation = [session fetchMessagesByUIDOperationWithFolder:folder requestKind:requestKind uids:uids];
[fetchOperation start:^(NSError * error, NSArray * fetchedMessages, MCOIndexSet * vanishedMessages)
{
if ( ! error ) {
for ( MCOIMAPMessage * message_ in fetchedMessages ) {
// I only want UNREAD messages.
}
}
}
I have tried using if ( message_.flags & MCOMessageFlagSeen )
but still, all flags return as 0.
What is the proper way to see if the message is UNREAD?
Upvotes: 1
Views: 1755
Reputation: 1
CMMessageSession *session = [CMessageManager shareManager].session;
MCOIMAPSession *imapSession = [session imapSession];
MCOIMAPFolderStatusOperation *folderOpera = [imapSession folderStatusOperation:folder];
if (!folderOpera) {
NSLog(@"获取imap邮箱状态失败");
[self fetchUnReadCountFromDB:folder complete:complete];
return;
}
[folderOpera start:^(NSError * _Nullable error, MCOIMAPFolderStatus * _Nullable status) {
if (error) {
NSLog(@"获取imap邮箱状态失败: %@", error.localizedDescription);
[self fetchUnReadCountFromDB:folder complete:complete];
return;
}
NSInteger count = status.unseenCount;
if (complete) {
complete(folder, count);
}
}];
Upvotes: -1
Reputation: 1441
You can use 0 or better as below, which is 0 too, but who knows if they decide to change it to something else later:
if(message_.flags == MCOMessageFlagNone)
Upvotes: 0
Reputation: 50707
For anyone having the same issue, you need to also include the kind request for flags: MCOIMAPMessagesRequestKindFlags
.
MCOIMAPMessagesRequestKind requestKind = MCOIMAPMessagesRequestKindHeaders|MCOIMAPMessagesRequestKindFlags;
Then, look for the unread flag:
for ( MCOIMAPMessage * message_ in fetchedMessages ) {
if ( message_.flags == 0 ) {
// I have a suspicion that this is not the correct
// way to do this, but it seems to work the way I need.
}
}
Upvotes: 6