aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/async/imap/MCIMAPFetchContentOperation.cpp
blob: 049ac8a7661a3ca5262f79d82beb82dc3559653b (plain)
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
//
//  IMAPFetchContentOperation.cc
//  mailcore2
//
//  Created by DINH Viêt Hoà on 1/12/13.
//  Copyright (c) 2013 MailCore. All rights reserved.
//

#include "MCIMAPFetchContentOperation.h"

#include "MCIMAPSession.h"
#include "MCIMAPAsyncConnection.h"

using namespace mailcore;

IMAPFetchContentOperation::IMAPFetchContentOperation()
{
    mUid = 0;
    mNumber = 0;
    mPartID = NULL;
    mEncoding = Encoding7Bit;
    mData = NULL;
}

IMAPFetchContentOperation::~IMAPFetchContentOperation()
{
    MC_SAFE_RELEASE(mPartID);
    MC_SAFE_RELEASE(mData);
}

void IMAPFetchContentOperation::setUid(uint32_t uid)
{
    mUid = uid;
}

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);
}

String * IMAPFetchContentOperation::partID()
{
    return mPartID;
}

void IMAPFetchContentOperation::setEncoding(Encoding encoding)
{
    mEncoding = encoding;
}

Encoding IMAPFetchContentOperation::encoding()
{
    return mEncoding;
}

Data * IMAPFetchContentOperation::data()
{
    return mData;
}

void IMAPFetchContentOperation::main()
{
    ErrorCode 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 {
        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);
}