Permalink
Browse files

Implement [CTCoreMessage isDeleted].

This cleans up some almost-copy-and-paste code at the same time.
  • Loading branch information...
1 parent 8fb4ed3 commit 905bf5aeaa6c4075545c562649d99bd563ba111c @ewanmellor ewanmellor committed May 26, 2013
Showing with 15 additions and 11 deletions.
  1. +5 −0 Source/CTCoreMessage.h
  2. +10 −11 Source/CTCoreMessage.m
@@ -164,6 +164,11 @@
- (NSDate *)senderDate;
/**
+ Returns YES if the message is deleted.
+ */
+- (BOOL)isDeleted;
+
+/**
Returns YES if the message is unread.
*/
- (BOOL)isUnread;
@@ -408,21 +408,20 @@ - (NSDate *)senderDate {
}
- (BOOL)isUnread {
- struct mail_flags *flags = myMessage ? myMessage->msg_flags : NULL;
- if (flags != NULL) {
- BOOL flag_seen = (flags->fl_flags & MAIL_FLAG_SEEN);
- return !flag_seen;
- }
- return NO;
+ return ![self isFlagSet:MAIL_FLAG_SEEN withDefault:YES];
+}
+
+- (BOOL)isDeleted {
+ return [self isFlagSet:MAIL_FLAG_DELETED withDefault:NO];
}
- (BOOL)isStarred {
+ return [self isFlagSet:MAIL_FLAG_FLAGGED withDefault:NO];
+}
+
+- (BOOL)isFlagSet:(NSUInteger)flag withDefault:(BOOL)def {
struct mail_flags *flags = myMessage ? myMessage->msg_flags : NULL;
- if (flags != NULL) {
- BOOL flag_starred = (flags->fl_flags & MAIL_FLAG_FLAGGED);
- return flag_starred;
- }
- return NO;
+ return flags == NULL ? def : flags->fl_flags & flag;
}
- (BOOL)isNew {

0 comments on commit 905bf5a

Please sign in to comment.