aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/async/imap/MCIMAPFetchContentToFileOperation.cpp
blob: e6bf7740dba877b1ea8dd6c9f65aefa3e5bb84dd (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
//
//  IMAPFetchContentToFileOperation.cpp
//  mailcore2
//
//  Created by Dmitry Isaikin on 2/08/16.
//  Copyright (c) 2016 MailCore. All rights reserved.
//

#include "MCIMAPFetchContentToFileOperation.h"

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

using namespace mailcore;

IMAPFetchContentToFileOperation::IMAPFetchContentToFileOperation()
{
    mUid = 0;
    mPartID = NULL;
    mEncoding = Encoding7Bit;
    mFilename = NULL;
    mLoadingByChunksEnabled = false;
    mChunksSize = 2*1024*1024;
    mEstimatedSize = 0;
}

IMAPFetchContentToFileOperation::~IMAPFetchContentToFileOperation()
{
    MC_SAFE_RELEASE(mPartID);
    MC_SAFE_RELEASE(mFilename);
}

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

void IMAPFetchContentToFileOperation::setPartID(String * partID)
{
    MC_SAFE_REPLACE_COPY(String, mPartID, partID);
}

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

void IMAPFetchContentToFileOperation::setFilename(String * filename)
{
    MC_SAFE_REPLACE_COPY(String, mFilename, filename);
}

void IMAPFetchContentToFileOperation::setLoadingByChunksEnabled(bool loadingByChunksEnabled)
{
    mLoadingByChunksEnabled = loadingByChunksEnabled;
}

bool IMAPFetchContentToFileOperation::isLoadingByChunksEnabled()
{
    return mLoadingByChunksEnabled;
}

void IMAPFetchContentToFileOperation::setChunksSize(uint32_t chunksSize)
{
    mChunksSize = chunksSize;
}

uint32_t IMAPFetchContentToFileOperation::chunksSize()
{
    return mChunksSize;
}

void IMAPFetchContentToFileOperation::setEstimatedSize(uint32_t estimatedSize)
{
    mEstimatedSize = estimatedSize;
}

uint32_t IMAPFetchContentToFileOperation::estimatedSize()
{
    return mEstimatedSize;
}

void IMAPFetchContentToFileOperation::main()
{
    ErrorCode error = ErrorNone;
    if (mLoadingByChunksEnabled) {
      session()->session()->fetchMessageAttachmentToFileByChunksByUID(folder(), mUid, mPartID,
                                                              mEstimatedSize, mEncoding,
                                                              mFilename, mChunksSize,
                                                              this, &error);
    } else {
      session()->session()->fetchMessageAttachmentToFileByUID(folder(), mUid, mPartID,
                                                              mEncoding, mFilename,
                                                              this, &error);
    }
    setError(error);
}