1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
//
// IMAPFetchMessagesOperation.cc
// mailcore2
//
// Created by DINH Viêt Hoà on 1/12/13.
// Copyright (c) 2013 MailCore. All rights reserved.
//
#include "MCIMAPFetchMessagesOperation.h"
#include "MCIMAPSession.h"
#include "MCIMAPAsyncConnection.h"
#include "MCIMAPSyncResult.h"
using namespace mailcore;
IMAPFetchMessagesOperation::IMAPFetchMessagesOperation()
{
mFetchByUidEnabled = false;
mIndexes = NULL;
mMessages = NULL;
mVanishedMessages = NULL;
mModSequenceValue = 0;
}
IMAPFetchMessagesOperation::~IMAPFetchMessagesOperation()
{
MC_SAFE_RELEASE(mIndexes);
MC_SAFE_RELEASE(mMessages);
MC_SAFE_RELEASE(mVanishedMessages);
}
void IMAPFetchMessagesOperation::setFetchByUidEnabled(bool enabled)
{
mFetchByUidEnabled = enabled;
}
bool IMAPFetchMessagesOperation::isFetchByUidEnabled()
{
return mFetchByUidEnabled;
}
void IMAPFetchMessagesOperation::setIndexes(IndexSet * indexes)
{
MC_SAFE_REPLACE_RETAIN(IndexSet, mIndexes, indexes);
}
IndexSet * IMAPFetchMessagesOperation::indexes()
{
return mIndexes;
}
void IMAPFetchMessagesOperation::setModSequenceValue(uint64_t modseq)
{
mModSequenceValue = modseq;
}
uint64_t IMAPFetchMessagesOperation::modSequenceValue()
{
return mModSequenceValue;
}
void IMAPFetchMessagesOperation::setKind(IMAPMessagesRequestKind kind)
{
mKind = kind;
}
IMAPMessagesRequestKind IMAPFetchMessagesOperation::kind()
{
return mKind;
}
Array * IMAPFetchMessagesOperation::messages()
{
return mMessages;
}
IndexSet * IMAPFetchMessagesOperation::vanishedMessages()
{
return mVanishedMessages;
}
void IMAPFetchMessagesOperation::main()
{
ErrorCode error;
if (mFetchByUidEnabled) {
if (mModSequenceValue != 0) {
IMAPSyncResult * syncResult;
syncResult = session()->session()->syncMessagesByUID(folder(), mKind, mIndexes, mModSequenceValue, this, &error);
if (syncResult != NULL) {
mMessages = syncResult->modifiedOrAddedMessages();
mVanishedMessages = syncResult->vanishedMessages();
}
}
else {
mMessages = session()->session()->fetchMessagesByUID(folder(), mKind, mIndexes, this, &error);
}
}
else {
mMessages = session()->session()->fetchMessagesByNumber(folder(), mKind, mIndexes, this, &error);
}
MC_SAFE_RETAIN(mMessages);
MC_SAFE_RETAIN(mVanishedMessages);
setError(error);
}
|