aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2014-10-14 22:20:58 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2014-10-14 22:20:58 -0700
commitf2e2bd964a01104fa0e265c817f9d41cd3f2bb65 (patch)
tree71d6435e2ebebf14d6c65000cba9a13046aa46f3
parent7e07d8ffb4f10fb25efbdd97946066e20fae245f (diff)
IMAP sequence number methods
-rwxr-xr-xexample/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.mm4
-rw-r--r--example/mac/macExample/macExample/MCTMsgListViewController.m2
-rw-r--r--example/mac/macExample/macExample/MCTMsgViewController.m4
-rwxr-xr-xsrc/async/imap/MCIMAPAsyncSession.cc54
-rwxr-xr-xsrc/async/imap/MCIMAPAsyncSession.h10
-rw-r--r--src/async/imap/MCIMAPFetchContentOperation.cc27
-rw-r--r--src/async/imap/MCIMAPFetchContentOperation.h4
-rw-r--r--src/async/imap/MCIMAPStoreFlagsOperation.cc19
-rw-r--r--src/async/imap/MCIMAPStoreFlagsOperation.h4
-rw-r--r--src/async/imap/MCIMAPStoreLabelsOperation.cc19
-rw-r--r--src/async/imap/MCIMAPStoreLabelsOperation.h4
-rw-r--r--src/core/imap/MCIMAPMessage.cc16
-rw-r--r--src/core/imap/MCIMAPMessage.h4
-rwxr-xr-xsrc/core/imap/MCIMAPSession.cc218
-rwxr-xr-xsrc/core/imap/MCIMAPSession.h22
-rw-r--r--src/objc/imap/MCOIMAPMessage.h4
-rw-r--r--src/objc/imap/MCOIMAPMessage.mm1
-rwxr-xr-xsrc/objc/imap/MCOIMAPSession.h261
-rwxr-xr-xsrc/objc/imap/MCOIMAPSession.mm156
19 files changed, 697 insertions, 136 deletions
diff --git a/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.mm b/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.mm
index ed41fd87..db8a1122 100755
--- a/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.mm
+++ b/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.mm
@@ -50,7 +50,7 @@
}
else {
[_messageView setMessage:NULL];
- MCOIMAPFetchContentOperation * op = [_session fetchMessageByUIDOperationWithFolder:_folder uid:[_message uid]];
+ MCOIMAPFetchContentOperation * op = [_session fetchMessageOperationWithFolder:_folder uid:[_message uid]];
[_ops addObject:op];
[op start:^(NSError * error, NSData * data) {
if ([error code] != MCOErrorNone) {
@@ -99,7 +99,7 @@
[_pending addObject:partUniqueID];
- MCOIMAPFetchContentOperation * op = [_session fetchMessageAttachmentByUIDOperationWithFolder:folder uid:[_message uid] partID:[part partID] encoding:[part encoding]];
+ MCOIMAPFetchContentOperation * op = [_session fetchMessageAttachmentOperationWithFolder:folder uid:[_message uid] partID:[part partID] encoding:[part encoding]];
[_ops addObject:op];
[op start:^(NSError * error, NSData * data) {
if ([error code] != MCOErrorNone) {
diff --git a/example/mac/macExample/macExample/MCTMsgListViewController.m b/example/mac/macExample/macExample/MCTMsgListViewController.m
index 0d7cee7a..01aad8ae 100644
--- a/example/mac/macExample/macExample/MCTMsgListViewController.m
+++ b/example/mac/macExample/macExample/MCTMsgListViewController.m
@@ -58,7 +58,7 @@
MCOIMAPMessagesRequestKindInternalDate | MCOIMAPMessagesRequestKindHeaderSubject |
MCOIMAPMessagesRequestKindFlags);
- _op = [_session fetchMessagesByUIDOperationWithFolder:FOLDER requestKind:requestKind uids:[MCOIndexSet indexSetWithRange:MCORangeMake(1, UINT64_MAX)]];
+ _op = [_session fetchMessagesOperationWithFolder:FOLDER requestKind:requestKind uids:[MCOIndexSet indexSetWithRange:MCORangeMake(1, UINT64_MAX)]];
[_op setProgress:^(unsigned int current){
//NSLog(@"progress: %u", current);
}];
diff --git a/example/mac/macExample/macExample/MCTMsgViewController.m b/example/mac/macExample/macExample/MCTMsgViewController.m
index f26b783f..67cc3892 100644
--- a/example/mac/macExample/macExample/MCTMsgViewController.m
+++ b/example/mac/macExample/macExample/MCTMsgViewController.m
@@ -49,7 +49,7 @@
}
else {
[_messageView setMessage:NULL];
- MCOIMAPFetchContentOperation * op = [_session fetchMessageByUIDOperationWithFolder:_folder uid:[_message uid]];
+ MCOIMAPFetchContentOperation * op = [_session fetchMessageOperationWithFolder:_folder uid:[_message uid]];
[_ops addObject:op];
[op start:^(NSError * error, NSData * data) {
if ([error code] != MCOErrorNone) {
@@ -84,7 +84,7 @@
[_pending addObject:partUniqueID];
- MCOIMAPFetchContentOperation * op = [_session fetchMessageAttachmentByUIDOperationWithFolder:folder uid:[_message uid] partID:[part partID] encoding:[part encoding]];
+ MCOIMAPFetchContentOperation * op = [_session fetchMessageAttachmentOperationWithFolder:folder uid:[_message uid] partID:[part partID] encoding:[part encoding]];
[_ops addObject:op];
[op start:^(NSError * error, NSData * data) {
if ([error code] != MCOErrorNone) {
diff --git a/src/async/imap/MCIMAPAsyncSession.cc b/src/async/imap/MCIMAPAsyncSession.cc
index 68625746..ef3bb621 100755
--- a/src/async/imap/MCIMAPAsyncSession.cc
+++ b/src/async/imap/MCIMAPAsyncSession.cc
@@ -524,7 +524,32 @@ IMAPFetchContentOperation * IMAPAsyncSession::fetchMessageAttachmentByUIDOperati
return op;
}
-IMAPOperation * IMAPAsyncSession::storeFlagsOperation(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags)
+IMAPFetchContentOperation * IMAPAsyncSession::fetchMessageByNumberOperation(String * folder, uint32_t number, bool urgent)
+{
+ IMAPFetchContentOperation * op = new IMAPFetchContentOperation();
+ op->setMainSession(this);
+ op->setFolder(folder);
+ op->setNumber(number);
+ op->setUrgent(urgent);
+ op->autorelease();
+ return op;
+}
+
+IMAPFetchContentOperation * IMAPAsyncSession::fetchMessageAttachmentByNumberOperation(String * folder, uint32_t number, String * partID,
+ Encoding encoding, bool urgent)
+{
+ IMAPFetchContentOperation * op = new IMAPFetchContentOperation();
+ op->setMainSession(this);
+ op->setFolder(folder);
+ op->setNumber(number);
+ op->setPartID(partID);
+ op->setEncoding(encoding);
+ op->setUrgent(urgent);
+ op->autorelease();
+ return op;
+}
+
+IMAPOperation * IMAPAsyncSession::storeFlagsByUIDOperation(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags)
{
IMAPStoreFlagsOperation * op = new IMAPStoreFlagsOperation();
op->setMainSession(this);
@@ -537,7 +562,20 @@ IMAPOperation * IMAPAsyncSession::storeFlagsOperation(String * folder, IndexSet
return op;
}
-IMAPOperation * IMAPAsyncSession::storeLabelsOperation(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, Array * labels)
+IMAPOperation * IMAPAsyncSession::storeFlagsByNumberOperation(String * folder, IndexSet * numbers, IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags)
+{
+ IMAPStoreFlagsOperation * op = new IMAPStoreFlagsOperation();
+ op->setMainSession(this);
+ op->setFolder(folder);
+ op->setNumbers(numbers);
+ op->setKind(kind);
+ op->setFlags(flags);
+ op->setCustomFlags(customFlags);
+ op->autorelease();
+ return op;
+}
+
+IMAPOperation * IMAPAsyncSession::storeLabelsByUIDOperation(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, Array * labels)
{
IMAPStoreLabelsOperation * op = new IMAPStoreLabelsOperation();
op->setMainSession(this);
@@ -549,6 +587,18 @@ IMAPOperation * IMAPAsyncSession::storeLabelsOperation(String * folder, IndexSet
return op;
}
+IMAPOperation * IMAPAsyncSession::storeLabelsByNumberOperation(String * folder, IndexSet * numbers, IMAPStoreFlagsRequestKind kind, Array * labels)
+{
+ IMAPStoreLabelsOperation * op = new IMAPStoreLabelsOperation();
+ op->setMainSession(this);
+ op->setFolder(folder);
+ op->setNumbers(numbers);
+ op->setKind(kind);
+ op->setLabels(labels);
+ op->autorelease();
+ return op;
+}
+
IMAPSearchOperation * IMAPAsyncSession::searchOperation(String * folder, IMAPSearchKind kind, String * searchString)
{
IMAPSearchOperation * op = new IMAPSearchOperation();
diff --git a/src/async/imap/MCIMAPAsyncSession.h b/src/async/imap/MCIMAPAsyncSession.h
index 333783b2..a7ec90a0 100755
--- a/src/async/imap/MCIMAPAsyncSession.h
+++ b/src/async/imap/MCIMAPAsyncSession.h
@@ -133,8 +133,14 @@ namespace mailcore {
virtual IMAPFetchContentOperation * fetchMessageAttachmentByUIDOperation(String * folder, uint32_t uid, String * partID,
Encoding encoding, bool urgent = false);
- virtual IMAPOperation * storeFlagsOperation(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags = NULL);
- virtual IMAPOperation * storeLabelsOperation(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, Array * labels);
+ virtual IMAPFetchContentOperation * fetchMessageByNumberOperation(String * folder, uint32_t number, bool urgent = false);
+ virtual IMAPFetchContentOperation * fetchMessageAttachmentByNumberOperation(String * folder, uint32_t number, String * partID,
+ Encoding encoding, bool urgent = false);
+
+ virtual IMAPOperation * storeFlagsByUIDOperation(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags = NULL);
+ virtual IMAPOperation * storeFlagsByNumberOperation(String * folder, IndexSet * numbers, IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags = NULL);
+ virtual IMAPOperation * storeLabelsByUIDOperation(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, Array * labels);
+ virtual IMAPOperation * storeLabelsByNumberOperation(String * folder, IndexSet * numbers, IMAPStoreFlagsRequestKind kind, Array * labels);
virtual IMAPSearchOperation * searchOperation(String * folder, IMAPSearchKind kind, String * searchString);
virtual IMAPSearchOperation * searchOperation(String * folder, IMAPSearchExpression * expression);
diff --git a/src/async/imap/MCIMAPFetchContentOperation.cc b/src/async/imap/MCIMAPFetchContentOperation.cc
index de3b911e..049ac8a7 100644
--- a/src/async/imap/MCIMAPFetchContentOperation.cc
+++ b/src/async/imap/MCIMAPFetchContentOperation.cc
@@ -16,6 +16,7 @@ using namespace mailcore;
IMAPFetchContentOperation::IMAPFetchContentOperation()
{
mUid = 0;
+ mNumber = 0;
mPartID = NULL;
mEncoding = Encoding7Bit;
mData = NULL;
@@ -37,6 +38,16 @@ uint32_t IMAPFetchContentOperation::uid()
return mUid;
}
+void IMAPFetchContentOperation::setNumber(uint32_t value)
+{
+ mNumber = value;
+}
+
+uint32_t IMAPFetchContentOperation::number()
+{
+ return mNumber;
+}
+
void IMAPFetchContentOperation::setPartID(String * partID)
{
MC_SAFE_REPLACE_COPY(String, mPartID, partID);
@@ -65,11 +76,21 @@ Data * IMAPFetchContentOperation::data()
void IMAPFetchContentOperation::main()
{
ErrorCode error;
- if (mPartID != NULL) {
- mData = session()->session()->fetchMessageAttachmentByUID(folder(), mUid, mPartID, mEncoding, this, &error);
+ if (mUid != 0) {
+ if (mPartID != NULL) {
+ mData = session()->session()->fetchMessageAttachmentByUID(folder(), mUid, mPartID, mEncoding, this, &error);
+ }
+ else {
+ mData = session()->session()->fetchMessageByUID(folder(), mUid, this, &error);
+ }
}
else {
- mData = session()->session()->fetchMessageByUID(folder(), mUid, this, &error);
+ if (mPartID != NULL) {
+ mData = session()->session()->fetchMessageAttachmentByNumber(folder(), mNumber, mPartID, mEncoding, this, &error);
+ }
+ else {
+ mData = session()->session()->fetchMessageByNumber(folder(), mNumber, this, &error);
+ }
}
MC_SAFE_RETAIN(mData);
setError(error);
diff --git a/src/async/imap/MCIMAPFetchContentOperation.h b/src/async/imap/MCIMAPFetchContentOperation.h
index 3d4dd17d..3cae3c5a 100644
--- a/src/async/imap/MCIMAPFetchContentOperation.h
+++ b/src/async/imap/MCIMAPFetchContentOperation.h
@@ -24,6 +24,9 @@ namespace mailcore {
virtual void setUid(uint32_t uid);
virtual uint32_t uid();
+ virtual void setNumber(uint32_t value);
+ virtual uint32_t number();
+
virtual void setPartID(String * partID);
virtual String * partID();
@@ -38,6 +41,7 @@ namespace mailcore {
private:
uint32_t mUid;
+ uint32_t mNumber;
String * mPartID;
Encoding mEncoding;
Data * mData;
diff --git a/src/async/imap/MCIMAPStoreFlagsOperation.cc b/src/async/imap/MCIMAPStoreFlagsOperation.cc
index df68529a..a049333e 100644
--- a/src/async/imap/MCIMAPStoreFlagsOperation.cc
+++ b/src/async/imap/MCIMAPStoreFlagsOperation.cc
@@ -16,6 +16,7 @@ using namespace mailcore;
IMAPStoreFlagsOperation::IMAPStoreFlagsOperation()
{
mUids = NULL;
+ mNumbers = NULL;
mKind = IMAPStoreFlagsRequestKindAdd;
mFlags = MessageFlagNone;
mCustomFlags = NULL;
@@ -23,6 +24,7 @@ IMAPStoreFlagsOperation::IMAPStoreFlagsOperation()
IMAPStoreFlagsOperation::~IMAPStoreFlagsOperation()
{
+ MC_SAFE_RELEASE(mNumbers);
MC_SAFE_RELEASE(mUids);
MC_SAFE_RELEASE(mCustomFlags);
}
@@ -37,6 +39,16 @@ IndexSet * IMAPStoreFlagsOperation::uids()
return mUids;
}
+void IMAPStoreFlagsOperation::setNumbers(IndexSet * numbers)
+{
+ MC_SAFE_REPLACE_RETAIN(IndexSet, mNumbers, numbers);
+}
+
+IndexSet * IMAPStoreFlagsOperation::numbers()
+{
+ return mNumbers;
+}
+
void IMAPStoreFlagsOperation::setKind(IMAPStoreFlagsRequestKind kind)
{
mKind = kind;
@@ -70,6 +82,11 @@ Array * IMAPStoreFlagsOperation::customFlags()
void IMAPStoreFlagsOperation::main()
{
ErrorCode error;
- session()->session()->storeFlagsAndCustomFlags(folder(), mUids, mKind, mFlags, mCustomFlags, &error);
+ if (mUids != NULL) {
+ session()->session()->storeFlagsAndCustomFlagsByUID(folder(), mUids, mKind, mFlags, mCustomFlags, &error);
+ }
+ else {
+ session()->session()->storeFlagsAndCustomFlagsByNumber(folder(), mNumbers, mKind, mFlags, mCustomFlags, &error);
+ }
setError(error);
}
diff --git a/src/async/imap/MCIMAPStoreFlagsOperation.h b/src/async/imap/MCIMAPStoreFlagsOperation.h
index f6219b30..1687f5cd 100644
--- a/src/async/imap/MCIMAPStoreFlagsOperation.h
+++ b/src/async/imap/MCIMAPStoreFlagsOperation.h
@@ -24,6 +24,9 @@ namespace mailcore {
virtual void setUids(IndexSet * uids);
virtual IndexSet * uids();
+ virtual void setNumbers(IndexSet * numbers);
+ virtual IndexSet * numbers();
+
virtual void setKind(IMAPStoreFlagsRequestKind kind);
virtual IMAPStoreFlagsRequestKind kind();
@@ -38,6 +41,7 @@ namespace mailcore {
private:
IndexSet * mUids;
+ IndexSet * mNumbers;
IMAPStoreFlagsRequestKind mKind;
MessageFlag mFlags;
Array * mCustomFlags;
diff --git a/src/async/imap/MCIMAPStoreLabelsOperation.cc b/src/async/imap/MCIMAPStoreLabelsOperation.cc
index ed738d11..3ad2212a 100644
--- a/src/async/imap/MCIMAPStoreLabelsOperation.cc
+++ b/src/async/imap/MCIMAPStoreLabelsOperation.cc
@@ -16,12 +16,14 @@ using namespace mailcore;
IMAPStoreLabelsOperation::IMAPStoreLabelsOperation()
{
mUids = NULL;
+ mNumbers = NULL;
mKind = IMAPStoreFlagsRequestKindAdd;
mLabels = NULL;
}
IMAPStoreLabelsOperation::~IMAPStoreLabelsOperation()
{
+ MC_SAFE_RELEASE(mNumbers);
MC_SAFE_RELEASE(mUids);
MC_SAFE_RELEASE(mLabels);
}
@@ -36,6 +38,16 @@ IndexSet * IMAPStoreLabelsOperation::uids()
return mUids;
}
+void IMAPStoreLabelsOperation::setNumbers(IndexSet * numbers)
+{
+ MC_SAFE_REPLACE_RETAIN(IndexSet, mNumbers, numbers);
+}
+
+IndexSet * IMAPStoreLabelsOperation::numbers()
+{
+ return mNumbers;
+}
+
void IMAPStoreLabelsOperation::setKind(IMAPStoreFlagsRequestKind kind)
{
mKind = kind;
@@ -59,7 +71,12 @@ Array * IMAPStoreLabelsOperation::labels()
void IMAPStoreLabelsOperation::main()
{
ErrorCode error;
- session()->session()->storeLabels(folder(), mUids, mKind, mLabels, &error);
+ if (mUids != NULL) {
+ session()->session()->storeLabelsByUID(folder(), mUids, mKind, mLabels, &error);
+ }
+ else {
+ session()->session()->storeLabelsByNumber(folder(), mUids, mKind, mLabels, &error);
+ }
setError(error);
}
diff --git a/src/async/imap/MCIMAPStoreLabelsOperation.h b/src/async/imap/MCIMAPStoreLabelsOperation.h
index 822cd83f..53348309 100644
--- a/src/async/imap/MCIMAPStoreLabelsOperation.h
+++ b/src/async/imap/MCIMAPStoreLabelsOperation.h
@@ -24,6 +24,9 @@ namespace mailcore {
virtual void setUids(IndexSet * uids);
virtual IndexSet * uids();
+ virtual void setNumbers(IndexSet * numbers);
+ virtual IndexSet * numbers();
+
virtual void setKind(IMAPStoreFlagsRequestKind kind);
virtual IMAPStoreFlagsRequestKind kind();
@@ -35,6 +38,7 @@ namespace mailcore {
private:
IndexSet * mUids;
+ IndexSet * mNumbers;
IMAPStoreFlagsRequestKind mKind;
Array * /* String */ mLabels;
diff --git a/src/core/imap/MCIMAPMessage.cc b/src/core/imap/MCIMAPMessage.cc
index 6cb1472c..7f393f32 100644
--- a/src/core/imap/MCIMAPMessage.cc
+++ b/src/core/imap/MCIMAPMessage.cc
@@ -16,6 +16,7 @@ static AbstractPart * partForPartIDInMessagePart(AbstractMessagePart * part, Str
void IMAPMessage::init()
{
mUid = 0;
+ mSequenceNumber = 0;
mFlags = MessageFlagNone;
mOriginalFlags = MessageFlagNone;
mCustomFlags = NULL;
@@ -35,6 +36,7 @@ IMAPMessage::IMAPMessage(IMAPMessage * other) : AbstractMessage(other)
{
init();
setUid(other->uid());
+ setSequenceNumber(other->sequenceNumber());
setFlags(other->flags());
setOriginalFlags(other->originalFlags());
setCustomFlags(other->customFlags());
@@ -59,7 +61,7 @@ Object * IMAPMessage::copy()
String * IMAPMessage::description()
{
String * result = String::string();
- result->appendUTF8Format("<%s:%p %u\n", className()->UTF8Characters(), this, (unsigned int) uid());
+ result->appendUTF8Format("<%s:%p %u %u\n", className()->UTF8Characters(), this, (unsigned int) uid(), (unsigned int) sequenceNumber());
result->appendString(header()->description());
if (mainPart() != NULL) {
result->appendString(mainPart()->description());
@@ -79,6 +81,16 @@ void IMAPMessage::setUid(uint32_t uid)
mUid = uid;
}
+uint32_t IMAPMessage::sequenceNumber()
+{
+ return mSequenceNumber;
+}
+
+void IMAPMessage::setSequenceNumber(uint32_t value)
+{
+ mSequenceNumber = value;
+}
+
uint32_t IMAPMessage::size()
{
return mSize;
@@ -235,6 +247,7 @@ String * IMAPMessage::htmlRendering(String * folder,
HashMap * IMAPMessage::serializable()
{
+ // sequenceNumber is not serialized.
HashMap * result = AbstractMessage::serializable();
result->setObjectForKey(MCSTR("modSeqValue"), String::stringWithUTF8Format("%llu", (long long unsigned) modSeqValue()));
result->setObjectForKey(MCSTR("uid"), String::stringWithUTF8Format("%lu", (long unsigned) uid()));
@@ -261,6 +274,7 @@ HashMap * IMAPMessage::serializable()
void IMAPMessage::importSerializable(HashMap * serializable)
{
+ // sequenceNumber is not serialized.
AbstractMessage::importSerializable(serializable);
String * modSeq = (String *) serializable->objectForKey(MCSTR("modSeqValue"));
if (modSeq != NULL) {
diff --git a/src/core/imap/MCIMAPMessage.h b/src/core/imap/MCIMAPMessage.h
index a78a04d6..b5266719 100644
--- a/src/core/imap/MCIMAPMessage.h
+++ b/src/core/imap/MCIMAPMessage.h
@@ -20,6 +20,9 @@ namespace mailcore {
IMAPMessage();
virtual ~IMAPMessage();
+ virtual uint32_t sequenceNumber();
+ virtual void setSequenceNumber(uint32_t sequenceNumber);
+
virtual uint32_t uid();
virtual void setUid(uint32_t uid);
@@ -70,6 +73,7 @@ namespace mailcore {
uint64_t mModSeqValue;
uint32_t mUid;
uint32_t mSize;
+ uint32_t mSequenceNumber; // not serialized.
MessageFlag mFlags;
MessageFlag mOriginalFlags;
diff --git a/src/core/imap/MCIMAPSession.cc b/src/core/imap/MCIMAPSession.cc
index be29d5fd..1c423eae 100755
--- a/src/core/imap/MCIMAPSession.cc
+++ b/src/core/imap/MCIMAPSession.cc
@@ -237,59 +237,6 @@ static Array * arrayFromSet(struct mailimap_set * imap_set)
return result;
}
-#if 0
-static int compareValuesUnsignedLong(void * value1, void * value2, void * context)
-{
- Value * concreteValue1 = (Value *) value1;
- Value * concreteValue2 = (Value *) value2;
-
- if (concreteValue2->unsignedLongValue() > concreteValue1->unsignedLongValue()) {
- return 1;
- }
- else if (concreteValue2->unsignedLongValue() < concreteValue1->unsignedLongValue()) {
- return -1;
- }
- else {
- return 0;
- }
-}
-
-static struct mailimap_set * setFromArray(Array * array)
-{
- unsigned int currentIndex = 0;
- unsigned int currentFirst = 0;
- unsigned int currentValue = 0;
- unsigned int lastValue = 0;
- struct mailimap_set * imap_set;
-
- array = array->sortedArray(compareValuesUnsignedLong, NULL);
- imap_set = mailimap_set_new_empty();
-
- while (currentIndex < array->count()) {
- currentValue = (unsigned int) ((Value *) array->objectAtIndex(currentIndex))->unsignedLongValue();
- if (currentFirst == 0) {
- currentFirst = currentValue;
- }
-
- if ((lastValue != 0) && (currentValue != lastValue + 1)) {
- mailimap_set_add_interval(imap_set, currentFirst, lastValue);
- currentFirst = 0;
- lastValue = 0;
- }
- else {
- lastValue = currentValue;
- currentIndex ++;
- }
- }
- if (currentFirst != 0) {
- mailimap_set_add_interval(imap_set, currentFirst, lastValue);
- }
-
- return imap_set;
-}
-
-#endif
-
static clist * splitSet(struct mailimap_set * set, unsigned int splitCount)
{
struct mailimap_set * current_set;
@@ -1778,7 +1725,7 @@ void IMAPSession::expunge(String * folder, ErrorCode * pError)
}
static int
-fetch_imap(mailimap * imap, uint32_t uid,
+fetch_imap(mailimap * imap, bool identifier_is_uid, uint32_t identifier,
struct mailimap_fetch_type * fetch_type,
char ** result, size_t * result_len)
{
@@ -1791,8 +1738,13 @@ fetch_imap(mailimap * imap, uint32_t uid,
size_t text_length;
clistiter * cur;
- set = mailimap_set_new_single(uid);
- r = mailimap_uid_fetch(imap, set, fetch_type, &fetch_result);
+ set = mailimap_set_new_single(identifier);
+ if (identifier_is_uid) {
+ r = mailimap_uid_fetch(imap, set, fetch_type, &fetch_result);
+ }
+ else {
+ r = mailimap_fetch(imap, set, fetch_type, &fetch_result);
+ }
mailimap_set_free(set);
@@ -1803,7 +1755,7 @@ fetch_imap(mailimap * imap, uint32_t uid,
return r;
}
- if (clist_begin(fetch_result) == NULL) {
+ if (clist_isempty(fetch_result)) {
mailimap_fetch_list_free(fetch_result);
return MAILIMAP_ERROR_FETCH;
}
@@ -1817,16 +1769,18 @@ fetch_imap(mailimap * imap, uint32_t uid,
cur = clist_next(cur)) {
msg_att_item = (struct mailimap_msg_att_item *) clist_content(cur);
- if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
-
- if (msg_att_item->att_data.att_static->att_type ==
- MAILIMAP_MSG_ATT_BODY_SECTION) {
- text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
- msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = NULL;
- text_length =
- msg_att_item->att_data.att_static->att_data.att_body_section->sec_length;
- }
+ if (msg_att_item->att_type != MAILIMAP_MSG_ATT_ITEM_STATIC) {
+ continue;
+ }
+
+ if (msg_att_item->att_data.att_static->att_type !=
+ MAILIMAP_MSG_ATT_BODY_SECTION) {
+ continue;
}
+
+ text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
+ msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = NULL;
+ text_length = msg_att_item->att_data.att_static->att_data.att_body_section->sec_length;
}
mailimap_fetch_list_free(fetch_result);
@@ -2486,9 +2440,23 @@ Array * IMAPSession::fetchMessagesByNumberWithExtraHeaders(String * folder, IMAP
return result;
}
-static int fetch_rfc822(mailimap * session,
- uint32_t msgid, char ** result)
+static int fetch_rfc822(mailimap * session, bool identifier_is_uid,
+ uint32_t identifier, char ** result, size_t * result_len)
{
+ struct mailimap_section * section;
+ struct mailimap_fetch_att * fetch_att;
+ struct mailimap_fetch_type * fetch_type;
+
+ section = mailimap_section_new(NULL);
+ fetch_att = mailimap_fetch_att_new_body_peek_section(section);
+ fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att);
+ int r = fetch_imap(session, identifier_is_uid, identifier,
+ fetch_type, result, result_len);
+ mailimap_fetch_type_free(fetch_type);
+
+ return r;
+
+#if 0
int r;
clist * fetch_list;
struct mailimap_section * section;
@@ -2504,9 +2472,14 @@ static int fetch_rfc822(mailimap * session,
fetch_att = mailimap_fetch_att_new_body_peek_section(section);
fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att);
- set = mailimap_set_new_single(msgid);
+ set = mailimap_set_new_single(identifier);
- r = mailimap_uid_fetch(session, set, fetch_type, &fetch_list);
+ if (identifier_is_uid) {
+ r = mailimap_uid_fetch(session, set, fetch_type, &fetch_list);
+ }
+ else {
+ r = mailimap_fetch(session, set, fetch_type, &fetch_list);
+ }
mailimap_set_free(set);
mailimap_fetch_type_free(fetch_type);
@@ -2546,27 +2519,41 @@ free:
mailimap_fetch_list_free(fetch_list);
err:
return res;
+#endif
}
Data * IMAPSession::fetchMessageByUID(String * folder, uint32_t uid,
IMAPProgressCallback * progressCallback, ErrorCode * pError)
{
+ return fetchMessage(folder, true, uid, progressCallback, pError);
+}
+
+Data * IMAPSession::fetchMessageByNumber(String * folder, uint32_t number,
+ IMAPProgressCallback * progressCallback, ErrorCode * pError)
+{
+ return fetchMessage(folder, false, number, progressCallback, pError);
+}
+
+Data * IMAPSession::fetchMessage(String * folder, bool identifier_is_uid, uint32_t identifier,
+ IMAPProgressCallback * progressCallback, ErrorCode * pError)
+{
char * rfc822;
+ size_t rfc822_len;
int r;
Data * data;
-
+
selectIfNeeded(folder, pError);
if (* pError != ErrorNone)
return NULL;
-
+
mProgressItemsCount = 0;
mProgressCallback = progressCallback;
-
+
rfc822 = NULL;
- r = fetch_rfc822(mImap, uid, &rfc822);
+ r = fetch_rfc822(mImap, identifier_is_uid, identifier, &rfc822, &rfc822_len);
if (r == MAILIMAP_NO_ERROR) {
size_t len;
-
+
len = 0;
if (rfc822 != NULL) {
len = strlen(rfc822);
@@ -2574,7 +2561,7 @@ Data * IMAPSession::fetchMessageByUID(String * folder, uint32_t uid,
bodyProgress((unsigned int) len, (unsigned int) len);
}
mProgressCallback = NULL;
-
+
if (r == MAILIMAP_ERROR_STREAM) {
mShouldDisconnect = true;
* pError = ErrorConnection;
@@ -2588,22 +2575,23 @@ Data * IMAPSession::fetchMessageByUID(String * folder, uint32_t uid,
* pError = ErrorFetch;
return NULL;
}
-
+
if (rfc822 == NULL) {
data = Data::data();
}
else {
- data = Data::dataWithBytes(rfc822, (unsigned int) strlen(rfc822));
+ data = Data::dataWithBytes(rfc822, (unsigned int) rfc822_len);
}
-
+
mailimap_nstring_free(rfc822);
* pError = ErrorNone;
-
+
return data;
}
-Data * IMAPSession::fetchMessageAttachmentByUID(String * folder, uint32_t uid, String * partID,
- Encoding encoding, IMAPProgressCallback * progressCallback, ErrorCode * pError)
+Data * IMAPSession::fetchMessageAttachment(String * folder, bool identifier_is_uid,
+ uint32_t identifier, String * partID,
+ Encoding encoding, IMAPProgressCallback * progressCallback, ErrorCode * pError)
{
struct mailimap_fetch_type * fetch_type;
struct mailimap_fetch_att * fetch_att;
@@ -2640,7 +2628,7 @@ Data * IMAPSession::fetchMessageAttachmentByUID(String * folder, uint32_t uid, S
fetch_att = mailimap_fetch_att_new_body_peek_section(section);
fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att);
- r = fetch_imap(mImap, uid, fetch_type, &text, &text_length);
+ r = fetch_imap(mImap, identifier_is_uid, identifier, fetch_type, &text, &text_length);
mailimap_fetch_type_free(fetch_type);
mProgressCallback = NULL;
@@ -2669,6 +2657,18 @@ Data * IMAPSession::fetchMessageAttachmentByUID(String * folder, uint32_t uid, S
return data;
}
+Data * IMAPSession::fetchMessageAttachmentByUID(String * folder, uint32_t uid, String * partID,
+ Encoding encoding, IMAPProgressCallback * progressCallback, ErrorCode * pError)
+{
+ return fetchMessageAttachment(folder, true, uid, partID, encoding, progressCallback, pError);
+}
+
+Data * IMAPSession::fetchMessageAttachmentByNumber(String * folder, uint32_t number, String * partID,
+ Encoding encoding, IMAPProgressCallback * progressCallback, ErrorCode * pError)
+{
+ return fetchMessageAttachment(folder, false, number, partID, encoding, progressCallback, pError);
+}
+
IndexSet * IMAPSession::search(String * folder, IMAPSearchKind kind, String * searchString, ErrorCode * pError)
{
IMAPSearchExpression * expr;
@@ -3301,12 +3301,18 @@ HashMap * IMAPSession::fetchNamespace(ErrorCode * pError)
return result;
}
-void IMAPSession::storeFlags(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, ErrorCode * pError)
+void IMAPSession::storeFlagsByUID(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, ErrorCode * pError)
{
- this->storeFlagsAndCustomFlags(folder, uids, kind, flags, NULL, pError);
+ this->storeFlagsAndCustomFlagsByUID(folder, uids, kind, flags, NULL, pError);
}
-void IMAPSession::storeFlagsAndCustomFlags(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags, ErrorCode * pError)
+void IMAPSession::storeFlagsAndCustomFlagsByUID(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags, ErrorCode * pError)
+{
+ storeFlagsAndCustomFlags(folder, true, uids, kind, flags, customFlags, pError);
+}
+
+void IMAPSession::storeFlagsAndCustomFlags(String * folder, bool identifier_is_uid, IndexSet * identifiers,
+ IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags, ErrorCode * pError)
{
struct mailimap_set * imap_set;
struct mailimap_store_att_flags * store_att_flags;
@@ -3318,7 +3324,7 @@ void IMAPSession::storeFlagsAndCustomFlags(String * folder, IndexSet * uids, IMA
if (* pError != ErrorNone)
return;
- imap_set = setFromIndexSet(uids);
+ imap_set = setFromIndexSet(identifiers);
if (clist_count(imap_set->set_list) == 0) {
mailimap_set_free(imap_set);
return;
@@ -3409,7 +3415,12 @@ void IMAPSession::storeFlagsAndCustomFlags(String * folder, IndexSet * uids, IMA
store_att_flags = mailimap_store_att_flags_new_set_flags_silent(flag_list);
break;
}
- r = mailimap_uid_store(mImap, current_set, store_att_flags);
+ if (identifier_is_uid) {
+ r = mailimap_uid_store(mImap, current_set, store_att_flags);
+ }
+ else {
+ r = mailimap_store(mImap, current_set, store_att_flags);
+ }
if (r == MAILIMAP_ERROR_STREAM) {
mShouldDisconnect = true;
@@ -3439,7 +3450,27 @@ void IMAPSession::storeFlagsAndCustomFlags(String * folder, IndexSet * uids, IMA
* pError = ErrorNone;
}
-void IMAPSession::storeLabels(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, Array * labels, ErrorCode * pError)
+void IMAPSession::storeFlagsByNumber(String * folder, IndexSet * numbers, IMAPStoreFlagsRequestKind kind, MessageFlag flags, ErrorCode * pError)
+{
+ this->storeFlagsAndCustomFlagsByNumber(folder, numbers, kind, flags, NULL, pError);
+}
+
+void IMAPSession::storeFlagsAndCustomFlagsByNumber(String * folder, IndexSet * numbers, IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags, ErrorCode * pError)
+{
+ storeFlagsAndCustomFlags(folder, false, numbers, kind, flags, customFlags, pError);
+}
+
+void IMAPSession::storeLabelsByUID(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, Array * labels, ErrorCode * pError)
+{
+ storeLabels(folder, true, uids, kind, labels, pError);
+}
+
+void IMAPSession::storeLabelsByNumber(String * folder, IndexSet * numbers, IMAPStoreFlagsRequestKind kind, Array * labels, ErrorCode * pError)
+{
+ storeLabels(folder, false, numbers, kind, labels, pError);
+}
+
+void IMAPSession::storeLabels(String * folder, bool identifier_is_uid, IndexSet * identifiers, IMAPStoreFlagsRequestKind kind, Array * labels, ErrorCode * pError)
{
struct mailimap_set * imap_set;
struct mailimap_msg_att_xgmlabels * xgmlabels;
@@ -3450,7 +3481,7 @@ void IMAPSession::storeLabels(String * folder, IndexSet * uids, IMAPStoreFlagsRe
if (* pError != ErrorNone)
return;
- imap_set = setFromIndexSet(uids);
+ imap_set = setFromIndexSet(identifiers);
if (clist_count(imap_set->set_list) == 0) {
mailimap_set_free(imap_set);
return;
@@ -3481,7 +3512,12 @@ void IMAPSession::storeLabels(String * folder, IndexSet * uids, IMAPStoreFlagsRe
fl_sign = 0;
break;
}
- r = mailimap_uid_store_xgmlabels(mImap, current_set, fl_sign, 1, xgmlabels);
+ if (identifier_is_uid) {
+ r = mailimap_uid_store_xgmlabels(mImap, current_set, fl_sign, 1, xgmlabels);
+ }
+ else {
+ r = mailimap_store_xgmlabels(mImap, current_set, fl_sign, 1, xgmlabels);
+ }
if (r == MAILIMAP_ERROR_STREAM) {
mShouldDisconnect = true;
* pError = ErrorConnection;
diff --git a/src/core/imap/MCIMAPSession.h b/src/core/imap/MCIMAPSession.h
index 6426fce8..591466fc 100755
--- a/src/core/imap/MCIMAPSession.h
+++ b/src/core/imap/MCIMAPSession.h
@@ -110,8 +110,12 @@ namespace mailcore {
virtual Data * fetchMessageByUID(String * folder, uint32_t uid,
IMAPProgressCallback * progressCallback, ErrorCode * pError);
+ virtual Data * fetchMessageByNumber(String * folder, uint32_t number,
+ IMAPProgressCallback * progressCallback, ErrorCode * pError);
virtual Data * fetchMessageAttachmentByUID(String * folder, uint32_t uid, String * partID,
Encoding encoding, IMAPProgressCallback * progressCallback, ErrorCode * pError);
+ virtual Data * fetchMessageAttachmentByNumber(String * folder, uint32_t number, String * partID,
+ Encoding encoding, IMAPProgressCallback * progressCallback, ErrorCode * pError);
virtual HashMap * fetchMessageNumberUIDMapping(String * folder, uint32_t fromUID, uint32_t toUID,
ErrorCode * pError);
@@ -125,9 +129,13 @@ namespace mailcore {
IMAPProgressCallback * progressCallback,
Array * extraHeaders, ErrorCode * pError);
- virtual void storeFlags(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, ErrorCode * pError);
- virtual void storeFlagsAndCustomFlags(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags, ErrorCode * pError);
- virtual void storeLabels(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, Array * labels, ErrorCode * pError);
+ virtual void storeFlagsByUID(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, ErrorCode * pError);
+ virtual void storeFlagsAndCustomFlagsByUID(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags, ErrorCode * pError);
+ virtual void storeFlagsByNumber(String * folder, IndexSet * numbers, IMAPStoreFlagsRequestKind kind, MessageFlag flags, ErrorCode * pError);
+ virtual void storeFlagsAndCustomFlagsByNumber(String * folder, IndexSet * numbers, IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags, ErrorCode * pError);
+
+ virtual void storeLabelsByUID(String * folder, IndexSet * uids, IMAPStoreFlagsRequestKind kind, Array * labels, ErrorCode * pError);
+ virtual void storeLabelsByNumber(String * folder, IndexSet * numbers, IMAPStoreFlagsRequestKind kind, Array * labels, ErrorCode * pError);
virtual IndexSet * search(String * folder, IMAPSearchKind kind, String * searchString, ErrorCode * pError);
virtual IndexSet * search(String * folder, IMAPSearchExpression * expression, ErrorCode * pError);
@@ -270,6 +278,14 @@ namespace mailcore {
void capabilitySetWithSessionState(IndexSet * capabilities);
bool enableFeature(String * feature);
void enableFeatures();
+ Data * fetchMessage(String * folder, bool identifier_is_uid, uint32_t identifier,
+ IMAPProgressCallback * progressCallback, ErrorCode * pError);
+ void storeFlagsAndCustomFlags(String * folder, bool identifier_is_uid, IndexSet * identifiers,
+ IMAPStoreFlagsRequestKind kind, MessageFlag flags, Array * customFlags, ErrorCode * pError);
+ Data * fetchMessageAttachment(String * folder, bool identifier_is_uid,
+ uint32_t identifier, String * partID,
+ Encoding encoding, IMAPProgressCallback * progressCallback, ErrorCode * pError);
+ void storeLabels(String * folder, bool identifier_is_uid, IndexSet * identifiers, IMAPStoreFlagsRequestKind kind, Array * labels, ErrorCode * pError);
};
}
diff --git a/src/objc/imap/MCOIMAPMessage.h b/src/objc/imap/MCOIMAPMessage.h
index 7ca40b9e..8e2e1c27 100644
--- a/src/objc/imap/MCOIMAPMessage.h
+++ b/src/objc/imap/MCOIMAPMessage.h
@@ -34,6 +34,10 @@
/** IMAP UID of the message. */
@property (nonatomic, assign) uint32_t uid;
+/** IMAP sequence number of the message.
+ @warning *Important*: This property won't be serialized. */
+@property (nonatomic, assign) uint32_t sequenceNumber;
+
/* Size of the entire message */
@property (nonatomic, assign) uint32_t size;
diff --git a/src/objc/imap/MCOIMAPMessage.mm b/src/objc/imap/MCOIMAPMessage.mm
index f663d8bd..d7d499ef 100644
--- a/src/objc/imap/MCOIMAPMessage.mm
+++ b/src/objc/imap/MCOIMAPMessage.mm
@@ -42,6 +42,7 @@
MCO_SYNTHESIZE_NSCODING
MCO_OBJC_SYNTHESIZE_SCALAR(uint32_t, uint32_t, setUid, uid)
+MCO_OBJC_SYNTHESIZE_SCALAR(uint32_t, uint32_t, setSequenceNumber, sequenceNumber)
MCO_OBJC_SYNTHESIZE_SCALAR(uint32_t, uint32_t, setSize, size)
MCO_OBJC_SYNTHESIZE_SCALAR(MCOMessageFlag, mailcore::MessageFlag, setFlags, flags)
MCO_OBJC_SYNTHESIZE_SCALAR(MCOMessageFlag, mailcore::MessageFlag, setOriginalFlags, originalFlags)
diff --git a/src/objc/imap/MCOIMAPSession.h b/src/objc/imap/MCOIMAPSession.h
index c9eafd87..e4ad33c2 100755
--- a/src/objc/imap/MCOIMAPSession.h
+++ b/src/objc/imap/MCOIMAPSession.h
@@ -326,6 +326,25 @@
uids:(MCOIndexSet *)uids
kind:(MCOIMAPStoreFlagsRequestKind)kind
flags:(MCOMessageFlag)flags;
+
+/**
+ Returns an operation to change flags of messages, using IMAP sequence number.
+
+ For example: Adds the seen flag to the message with the sequence number number 42.
+
+ MCOIMAPOperation * op = [session storeFlagsOperationWithFolder:@"INBOX"
+ numbers:[MCOIndexSet indexSetWithIndex:42]
+ kind:MCOIMAPStoreFlagsRequestKindAdd
+ flags:MCOMessageFlagSeen];
+ [op start:^(NSError * error) {
+ ...
+ }];
+ */
+- (MCOIMAPOperation *) storeFlagsOperationWithFolder:(NSString *)folder
+ numbers:(MCOIndexSet *)uinumbersds
+ kind:(MCOIMAPStoreFlagsRequestKind)kind
+ flags:(MCOMessageFlag)flags;
+
/**
Returns an operation to change flags and custom flags of messages.
@@ -345,15 +364,55 @@
kind:(MCOIMAPStoreFlagsRequestKind)kind
flags:(MCOMessageFlag)flags
customFlags:(NSArray *)customFlags;
+
+
+/**
+ Returns an operation to change flags and custom flags of messages, using IMAP sequence number.
+
+ For example: Adds the seen flag and $CNS-Greeting-On flag to the message with the sequence number 42.
+
+ MCOIMAPOperation * op = [session storeFlagsOperationWithFolder:@"INBOX"
+ numbers:[MCOIndexSet indexSetWithIndex:42]
+ kind:MCOIMAPStoreFlagsRequestKindAdd
+ flags:MCOMessageFlagSeen
+ customFlags:@["$CNS-Greeting-On"]];
+ [op start:^(NSError * error) {
+ ...
+ }];
+ */
+- (MCOIMAPOperation *) storeFlagsOperationWithFolder:(NSString *)folder
+ numbers:(MCOIndexSet *)numbers
+ kind:(MCOIMAPStoreFlagsRequestKind)kind
+ flags:(MCOMessageFlag)flags
+ customFlags:(NSArray *)customFlags;
+
+/**
+ Returns an operation to change labels of messages. Intended for Gmail
+
+ For example: Adds the label "Home" flag to the message with UID 42.
+
+ MCOIMAPOperation * op = [session storeLabelsOperationWithFolder:@"INBOX"
+ numbers:[MCOIndexSet indexSetWithIndex:42]
+ kind:MCOIMAPStoreFlagsRequestKindAdd
+ labels:[NSArray arrayWithObject:@"Home"]];
+ [op start:^(NSError * error) {
+ ...
+ }];
+*/
+- (MCOIMAPOperation *) storeLabelsOperationWithFolder:(NSString *)folder
+ numbers:(MCOIndexSet *)numbers
+ kind:(MCOIMAPStoreFlagsRequestKind)kind
+ labels:(NSArray *)labels;
+
/**
Returns an operation to change labels of messages. Intended for Gmail
For example: Adds the label "Home" flag to the message with UID 456.
- MCOIMAPOperation * op = [session storeFlagsOperationWithFolder:@"INBOX"
- uids:[MCOIndexSet indexSetWithIndex:456]
- kind:MCOIMAPStoreFlagsRequestKindAdd
- labels:[NSArray arrayWithObject:@"Home"]];
+ MCOIMAPOperation * op = [session storeLabelsOperationWithFolder:@"INBOX"
+ uids:[MCOIndexSet indexSetWithIndex:456]
+ kind:MCOIMAPStoreFlagsRequestKindAdd
+ labels:[NSArray arrayWithObject:@"Home"]];
[op start:^(NSError * error) {
...
}];
@@ -379,7 +438,23 @@
*/
- (MCOIMAPFetchMessagesOperation *) fetchMessagesByUIDOperationWithFolder:(NSString *)folder
requestKind:(MCOIMAPMessagesRequestKind)requestKind
- uids:(MCOIndexSet *)uids;
+ uids:(MCOIndexSet *)uids DEPRECATED_ATTRIBUTE;
+
+/**
+ Returns an operation to fetch messages by UID.
+
+ MCOIMAPFetchMessagesOperation * op = [session fetchMessagesOperationWithFolder:@"INBOX"
+ requestKind:MCOIMAPMessagesRequestKindHeaders | MCOIMAPMessagesRequestKindStructure
+ uids:MCORangeMake(1, UINT64_MAX)];
+ [op start:^(NSError * error, NSArray * messages, MCOIndexSet * vanishedMessages) {
+ for(MCOIMAPMessage * msg in messages) {
+ NSLog(@"%lu: %@", [msg uid], [msg header]);
+ }
+ }];
+*/
+- (MCOIMAPFetchMessagesOperation *) fetchMessagesOperationWithFolder:(NSString *)folder
+ requestKind:(MCOIMAPMessagesRequestKind)requestKind
+ uids:(MCOIndexSet *)uids;
/**
Returns an operation to fetch messages by (sequence) number.
@@ -425,7 +500,27 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162
- (MCOIMAPFetchMessagesOperation *) syncMessagesByUIDWithFolder:(NSString *)folder
requestKind:(MCOIMAPMessagesRequestKind)requestKind
uids:(MCOIndexSet *)uids
- modSeq:(uint64_t)modSeq;
+ modSeq:(uint64_t)modSeq DEPRECATED_ATTRIBUTE;
+
+/**
+ Returns an operation to sync the last changes related to the given message list given a modSeq.
+
+ MCOIMAPFetchMessagesOperation * op = [session syncMessagesWithFolder:@"INBOX"
+ requestKind:MCOIMAPMessagesRequestKindUID
+ uids:MCORangeMake(1, UINT64_MAX)
+ modSeq:lastModSeq];
+ [op start:^(NSError * error, NSArray * messages, MCOIndexSet * vanishedMessages) {
+ NSLog(@"added or modified messages: %@", messages);
+ NSLog(@"deleted messages: %@", vanishedMessages);
+ }];
+
+@warn *Important*: This is only for servers that support Conditional Store. See [RFC4551](http://tools.ietf.org/html/rfc4551)
+vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162](http://tools.ietf.org/html/rfc5162)
+*/
+- (MCOIMAPFetchMessagesOperation *) syncMessagesWithFolder:(NSString *)folder
+ requestKind:(MCOIMAPMessagesRequestKind)requestKind
+ uids:(MCOIndexSet *)uids
+ modSeq:(uint64_t)modSeq;
/**
Returns an operation to fetch the content of a message.
@@ -439,7 +534,7 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162
*/
- (MCOIMAPFetchContentOperation *) fetchMessageByUIDOperationWithFolder:(NSString *)folder
uid:(uint32_t)uid
- urgent:(BOOL)urgent;
+ urgent:(BOOL)urgent DEPRECATED_ATTRIBUTE;
/**
Returns an operation to fetch the content of a message.
@@ -451,7 +546,59 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162
}];
*/
- (MCOIMAPFetchContentOperation *) fetchMessageByUIDOperationWithFolder:(NSString *)folder
- uid:(uint32_t)uid;
+ uid:(uint32_t)uid DEPRECATED_ATTRIBUTE;
+
+/**
+ Returns an operation to fetch the content of a message.
+ @param urgent is set to YES, an additional connection to the same folder might be opened to fetch the content.
+
+ MCOIMAPFetchContentOperation * op = [session fetchMessageOperationWithFolder:@"INBOX" uid:456 urgent:NO];
+ [op start:^(NSError * error, NSData * messageData) {
+ MCOMessageParser * parser = [MCOMessageParser messageParserWithData:messageData]
+ ...
+ }];
+ */
+- (MCOIMAPFetchContentOperation *) fetchMessageOperationWithFolder:(NSString *)folder
+ uid:(uint32_t)uid
+ urgent:(BOOL)urgent;
+
+/**
+ Returns an operation to fetch the content of a message.
+
+ MCOIMAPFetchContentOperation * op = [session fetchMessageOperationWithFolder:@"INBOX" uid:456];
+ [op start:^(NSError * error, NSData * messageData) {
+ MCOMessageParser * parser = [MCOMessageParser messageParserWithData:messageData]
+ ...
+ }];
+ */
+- (MCOIMAPFetchContentOperation *) fetchMessageOperationWithFolder:(NSString *)folder
+ uid:(uint32_t)uid;
+
+/**
+ Returns an operation to fetch the content of a message, using IMAP sequence number.
+ @param urgent is set to YES, an additional connection to the same folder might be opened to fetch the content.
+
+ MCOIMAPFetchContentOperation * op = [session fetchMessageOperationWithFolder:@"INBOX" number:42 urgent:NO];
+ [op start:^(NSError * error, NSData * messageData) {
+ MCOMessageParser * parser = [MCOMessageParser messageParserWithData:messageData]
+ ...
+ }];
+*/
+- (MCOIMAPFetchContentOperation *) fetchMessageOperationWithFolder:(NSString *)folder
+ number:(uint32_t)number
+ urgent:(BOOL)urgent;
+
+/**
+ Returns an operation to fetch the content of a message, using IMAP sequence number.
+
+ MCOIMAPFetchContentOperation * op = [session fetchMessageOperationWithFolder:@"INBOX" number:42];
+ [op start:^(NSError * error, NSData * messageData) {
+ MCOMessageParser * parser = [MCOMessageParser messageParserWithData:messageData]
+ ...
+ }];
+*/
+- (MCOIMAPFetchContentOperation *) fetchMessageOperationWithFolder:(NSString *)folder
+ number:(uint32_t)number;
/** @name Fetching Attachment Operations */
@@ -472,7 +619,7 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162
uid:(uint32_t)uid
partID:(NSString *)partID
encoding:(MCOEncoding)encoding
- urgent:(BOOL)urgent;
+ urgent:(BOOL)urgent DEPRECATED_ATTRIBUTE;
/**
Returns an operation to fetch an attachment.
@@ -500,7 +647,101 @@ vanishedMessages will be set only for servers that support QRESYNC. See [RFC5162
- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentByUIDOperationWithFolder:(NSString *)folder
uid:(uint32_t)uid
partID:(NSString *)partID
- encoding:(MCOEncoding)encoding;
+ encoding:(MCOEncoding)encoding DEPRECATED_ATTRIBUTE;
+
+/**
+ Returns an operation to fetch an attachment.
+ @param urgent is set to YES, an additional connection to the same folder might be opened to fetch the content.
+
+ MCOIMAPFetchContentOperation * op = [session fetchMessageAttachmentOperationWithFolder:@"INBOX"
+ uid:456
+ partID:@"1.2"
+ encoding:MCOEncodingBase64
+ urgent:YES];
+ [op start:^(NSError * error, NSData * partData) {
+ ...
+ }];
+*/
+- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentOperationWithFolder:(NSString *)folder
+ uid:(uint32_t)uid
+ partID:(NSString *)partID
+ encoding:(MCOEncoding)encoding
+ urgent:(BOOL)urgent;
+
+/**
+ Returns an operation to fetch an attachment.
+
+ Example 1:
+
+ MCOIMAPFetchContentOperation * op = [session fetchMessageAttachmentOperationWithFolder:@"INBOX"
+ uid:456
+ partID:@"1.2"
+ encoding:MCOEncodingBase64];
+ [op start:^(NSError * error, NSData * partData) {
+ ...
+ }];
+
+ Example 2:
+
+ MCOIMAPFetchContentOperation * op = [session fetchMessageAttachmentOperationWithFolder:@"INBOX"
+ uid:[message uid]
+ partID:[part partID]
+ encoding:[part encoding]];
+ [op start:^(NSError * error, NSData * partData) {
+ ...
+ }];
+*/
+- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentOperationWithFolder:(NSString *)folder
+ uid:(uint32_t)uid
+ partID:(NSString *)partID
+ encoding:(MCOEncoding)encoding;
+
+/**
+ Returns an operation to fetch an attachment.
+ @param urgent is set to YES, an additional connection to the same folder might be opened to fetch the content.
+
+ MCOIMAPFetchContentOperation * op = [session fetchMessageAttachmentOperationWithFolder:@"INBOX"
+ uid:456
+ partID:@"1.2"
+ encoding:MCOEncodingBase64
+ urgent:YES];
+ [op start:^(NSError * error, NSData * partData) {
+ ...
+ }];
+*/
+- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentOperationWithFolder:(NSString *)folder
+ number:(uint32_t)number
+ partID:(NSString *)partID
+ encoding:(MCOEncoding)encoding
+ urgent:(BOOL)urgent;
+
+/**
+ Returns an operation to fetch an attachment.
+
+ Example 1:
+
+ MCOIMAPFetchContentOperation * op = [session fetchMessageAttachmentOperationWithFolder:@"INBOX"
+ number:42
+ partID:@"1.2"
+ encoding:MCOEncodingBase64];
+ [op start:^(NSError * error, NSData * partData) {
+ ...
+ }];
+
+ Example 2:
+
+ MCOIMAPFetchContentOperation * op = [session fetchMessageAttachmentOperationWithFolder:@"INBOX"
+ number:[message sequenceNumber]
+ partID:[part partID]
+ encoding:[part encoding]];
+ [op start:^(NSError * error, NSData * partData) {
+ ...
+ }];
+*/
+- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentOperationWithFolder:(NSString *)folder
+ number:(uint32_t)number
+ partID:(NSString *)partID
+ encoding:(MCOEncoding)encoding;
/** @name General IMAP Actions */
diff --git a/src/objc/imap/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm
index dddb27fa..c7c389a4 100755
--- a/src/objc/imap/MCOIMAPSession.mm
+++ b/src/objc/imap/MCOIMAPSession.mm
@@ -285,6 +285,13 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
requestKind:(MCOIMAPMessagesRequestKind)requestKind
uids:(MCOIndexSet *)uids
{
+ return [self fetchMessagesOperationWithFolder:folder requestKind:requestKind uids:uids];
+}
+
+- (MCOIMAPFetchMessagesOperation *) fetchMessagesOperationWithFolder:(NSString *)folder
+ requestKind:(MCOIMAPMessagesRequestKind)requestKind
+ uids:(MCOIndexSet *)uids
+{
IMAPFetchMessagesOperation * coreOp = MCO_NATIVE_INSTANCE->fetchMessagesByUIDOperation([folder mco_mcString],
(IMAPMessagesRequestKind) requestKind,
MCO_FROM_OBJC(IndexSet, uids));
@@ -306,6 +313,14 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
uids:(MCOIndexSet *)uids
modSeq:(uint64_t)modSeq
{
+ return [self syncMessagesWithFolder:folder requestKind:requestKind uids:uids modSeq:modSeq];
+}
+
+- (MCOIMAPFetchMessagesOperation *) syncMessagesWithFolder:(NSString *)folder
+ requestKind:(MCOIMAPMessagesRequestKind)requestKind
+ uids:(MCOIndexSet *)uids
+ modSeq:(uint64_t)modSeq
+{
IMAPFetchMessagesOperation * coreOp = MCO_NATIVE_INSTANCE->syncMessagesByUID([folder mco_mcString],
(IMAPMessagesRequestKind) requestKind,
MCO_FROM_OBJC(IndexSet, uids),
@@ -317,14 +332,41 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
uid:(uint32_t)uid
urgent:(BOOL)urgent
{
- IMAPFetchContentOperation * coreOp = MCO_NATIVE_INSTANCE->fetchMessageByUIDOperation([folder mco_mcString], uid, urgent);
- return MCO_TO_OBJC_OP(coreOp);
+ return [self fetchMessageOperationWithFolder:folder uid:uid urgent:urgent];
}
- (MCOIMAPFetchContentOperation *) fetchMessageByUIDOperationWithFolder:(NSString *)folder
uid:(uint32_t)uid
{
- return [self fetchMessageByUIDOperationWithFolder:folder uid:uid urgent:NO];
+ return [self fetchMessageOperationWithFolder:folder uid:uid];
+}
+
+- (MCOIMAPFetchContentOperation *) fetchMessageOperationWithFolder:(NSString *)folder
+ uid:(uint32_t)uid
+ urgent:(BOOL)urgent
+{
+ IMAPFetchContentOperation * coreOp = MCO_NATIVE_INSTANCE->fetchMessageByUIDOperation([folder mco_mcString], uid, urgent);
+ return MCO_TO_OBJC_OP(coreOp);
+}
+
+- (MCOIMAPFetchContentOperation *) fetchMessageOperationWithFolder:(NSString *)folder
+ uid:(uint32_t)uid
+{
+ return [self fetchMessageOperationWithFolder:folder uid:uid urgent:NO];
+}
+
+- (MCOIMAPFetchContentOperation *) fetchMessageOperationWithFolder:(NSString *)folder
+ number:(uint32_t)number
+ urgent:(BOOL)urgent
+{
+ IMAPFetchContentOperation * coreOp = MCO_NATIVE_INSTANCE->fetchMessageByNumberOperation([folder mco_mcString], number, urgent);
+ return MCO_TO_OBJC_OP(coreOp);
+}
+
+- (MCOIMAPFetchContentOperation *) fetchMessageOperationWithFolder:(NSString *)folder
+ number:(uint32_t)number
+{
+ return [self fetchMessageOperationWithFolder:folder number:number urgent:NO];
}
- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentByUIDOperationWithFolder:(NSString *)folder
@@ -333,6 +375,30 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
encoding:(MCOEncoding)encoding
urgent:(BOOL)urgent
{
+ return [self fetchMessageAttachmentOperationWithFolder:folder
+ uid:uid
+ partID:partID
+ encoding:encoding
+ urgent:urgent];
+}
+
+- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentByUIDOperationWithFolder:(NSString *)folder
+ uid:(uint32_t)uid
+ partID:(NSString *)partID
+ encoding:(MCOEncoding)encoding
+{
+ return [self fetchMessageAttachmentOperationWithFolder:folder
+ uid:uid
+ partID:partID
+ encoding:encoding];
+}
+
+- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentOperationWithFolder:(NSString *)folder
+ uid:(uint32_t)uid
+ partID:(NSString *)partID
+ encoding:(MCOEncoding)encoding
+ urgent:(BOOL)urgent
+{
IMAPFetchContentOperation * coreOp = MCO_NATIVE_INSTANCE->fetchMessageAttachmentByUIDOperation([folder mco_mcString],
uid,
[partID mco_mcString],
@@ -341,12 +407,34 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
return MCO_TO_OBJC_OP(coreOp);
}
-- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentByUIDOperationWithFolder:(NSString *)folder
- uid:(uint32_t)uid
- partID:(NSString *)partID
- encoding:(MCOEncoding)encoding
+- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentOperationWithFolder:(NSString *)folder
+ uid:(uint32_t)uid
+ partID:(NSString *)partID
+ encoding:(MCOEncoding)encoding
+{
+ return [self fetchMessageAttachmentOperationWithFolder:folder uid:uid partID:partID encoding:encoding urgent:NO];
+}
+
+- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentOperationWithFolder:(NSString *)folder
+ number:(uint32_t)number
+ partID:(NSString *)partID
+ encoding:(MCOEncoding)encoding
+ urgent:(BOOL)urgent
+{
+ IMAPFetchContentOperation * coreOp = MCO_NATIVE_INSTANCE->fetchMessageAttachmentByNumberOperation([folder mco_mcString],
+ number,
+ [partID mco_mcString],
+ (Encoding) encoding,
+ urgent);
+ return MCO_TO_OBJC_OP(coreOp);
+}
+
+- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentOperationWithFolder:(NSString *)folder
+ number:(uint32_t)number
+ partID:(NSString *)partID
+ encoding:(MCOEncoding)encoding
{
- return [self fetchMessageAttachmentByUIDOperationWithFolder:folder uid:uid partID:partID encoding:encoding urgent:NO];
+ return [self fetchMessageAttachmentOperationWithFolder:folder number:number partID:partID encoding:encoding urgent:NO];
}
- (MCOIMAPOperation *) storeFlagsOperationWithFolder:(NSString *)folder
@@ -363,11 +451,33 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
flags:(MCOMessageFlag)flags
customFlags:(NSArray *)customFlags
{
- IMAPOperation * coreOp = MCO_NATIVE_INSTANCE->storeFlagsOperation([folder mco_mcString],
- MCO_FROM_OBJC(IndexSet, uids),
- (IMAPStoreFlagsRequestKind) kind,
- (MessageFlag) flags,
- MCO_FROM_OBJC(Array, customFlags));
+ IMAPOperation * coreOp = MCO_NATIVE_INSTANCE->storeFlagsByUIDOperation([folder mco_mcString],
+ MCO_FROM_OBJC(IndexSet, uids),
+ (IMAPStoreFlagsRequestKind) kind,
+ (MessageFlag) flags,
+ MCO_FROM_OBJC(Array, customFlags));
+ return OPAQUE_OPERATION(coreOp);
+}
+
+- (MCOIMAPOperation *) storeFlagsOperationWithFolder:(NSString *)folder
+ numbers:(MCOIndexSet *)numbers
+ kind:(MCOIMAPStoreFlagsRequestKind)kind
+ flags:(MCOMessageFlag)flags
+{
+ return [self storeFlagsOperationWithFolder:folder numbers:numbers kind:kind flags:flags customFlags:NULL];
+}
+
+- (MCOIMAPOperation *) storeFlagsOperationWithFolder:(NSString *)folder
+ numbers:(MCOIndexSet *)numbers
+ kind:(MCOIMAPStoreFlagsRequestKind)kind
+ flags:(MCOMessageFlag)flags
+ customFlags:(NSArray *)customFlags
+{
+ IMAPOperation * coreOp = MCO_NATIVE_INSTANCE->storeFlagsByNumberOperation([folder mco_mcString],
+ MCO_FROM_OBJC(IndexSet, numbers),
+ (IMAPStoreFlagsRequestKind) kind,
+ (MessageFlag) flags,
+ MCO_FROM_OBJC(Array, customFlags));
return OPAQUE_OPERATION(coreOp);
}
@@ -376,10 +486,22 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
kind:(MCOIMAPStoreFlagsRequestKind)kind
labels:(NSArray *)labels
{
- IMAPOperation * coreOp = MCO_NATIVE_INSTANCE->storeLabelsOperation([folder mco_mcString],
- MCO_FROM_OBJC(IndexSet, uids),
- (IMAPStoreFlagsRequestKind) kind,
- MCO_FROM_OBJC(Array, labels));
+ IMAPOperation * coreOp = MCO_NATIVE_INSTANCE->storeLabelsByUIDOperation([folder mco_mcString],
+ MCO_FROM_OBJC(IndexSet, uids),
+ (IMAPStoreFlagsRequestKind) kind,
+ MCO_FROM_OBJC(Array, labels));
+ return OPAQUE_OPERATION(coreOp);
+}
+
+- (MCOIMAPOperation *) storeLabelsOperationWithFolder:(NSString *)folder
+ numbers:(MCOIndexSet *)numbers
+ kind:(MCOIMAPStoreFlagsRequestKind)kind
+ labels:(NSArray *)labels
+{
+ IMAPOperation * coreOp = MCO_NATIVE_INSTANCE->storeLabelsByNumberOperation([folder mco_mcString],
+ MCO_FROM_OBJC(IndexSet, numbers),
+ (IMAPStoreFlagsRequestKind) kind,
+ MCO_FROM_OBJC(Array, labels));
return OPAQUE_OPERATION(coreOp);
}