diff options
author | Dmitry Isaikin <isaikin-dmitry@yandex.ru> | 2016-07-06 10:17:28 +0300 |
---|---|---|
committer | HoĆ V. DINH <dinh.viet.hoa@gmail.com> | 2016-07-06 00:17:28 -0700 |
commit | 1e77049bf421997de9d04a6d1e1dde4ce065affe (patch) | |
tree | f6358a20850a4f440d870ec857428c7f071160cf /src/core/imap/MCIMAPSession.cpp | |
parent | 17df6ae7c456cc27a316aa0d7b6c83066adb3c49 (diff) |
Use libetpan API for fetching whole IMAP attachment to file (#1461)
Diffstat (limited to 'src/core/imap/MCIMAPSession.cpp')
-rw-r--r-- | src/core/imap/MCIMAPSession.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src/core/imap/MCIMAPSession.cpp b/src/core/imap/MCIMAPSession.cpp index e58b8cba..a5a5e06c 100644 --- a/src/core/imap/MCIMAPSession.cpp +++ b/src/core/imap/MCIMAPSession.cpp @@ -2973,7 +2973,7 @@ Data * IMAPSession::fetchMessageAttachmentByNumber(String * folder, uint32_t num return fetchMessageAttachment(folder, false, number, partID, encoding, progressCallback, pError); } -void IMAPSession::fetchMessageAttachmentToFileByUID(String * folder, uint32_t uid, String * partID, +void IMAPSession::fetchMessageAttachmentToFileByChunksByUID(String * folder, uint32_t uid, String * partID, uint32_t estimatedSize, Encoding encoding, String * outputFile, uint32_t chunkSize, IMAPProgressCallback * progressCallback, ErrorCode * pError) @@ -3051,6 +3051,51 @@ void IMAPSession::fetchMessageAttachmentToFileByUID(String * folder, uint32_t ui * pError = error; } +static bool msg_body_handler(int msg_att_type, struct mailimap_msg_att_body_section * section, + const char * bytes, size_t len, void * context) +{ + DataStreamDecoder * decoder = (DataStreamDecoder *)context; + + AutoreleasePool * pool = new AutoreleasePool(); + + Data * data = Data::dataWithBytes(bytes, (unsigned int) len); + ErrorCode error = decoder->appendData(data); + + pool->release(); + + return error == ErrorNone; +} + +void IMAPSession::fetchMessageAttachmentToFileByUID(String * folder, uint32_t uid, String * partID, + Encoding encoding, String * outputFile, + IMAPProgressCallback * progressCallback, ErrorCode * pError) +{ + DataStreamDecoder * decoder = new DataStreamDecoder(); + decoder->setEncoding(encoding); + decoder->setFilename(outputFile); + + ErrorCode error = ErrorNone; + selectIfNeeded(folder, &error); + if (error != ErrorNone) { + * pError = error; + return; + } + + mailimap_set_msg_body_handler(mImap, msg_body_handler, decoder); + + fetchNonDecodedMessageAttachment(folder, true, uid, partID, true, 0, 0, encoding, progressCallback, &error); + + mailimap_set_msg_body_handler(mImap, NULL, NULL); + + if (error == ErrorNone) { + error = decoder->flushData(); + } + + MC_SAFE_RELEASE(decoder); + + * pError = error; +} + IndexSet * IMAPSession::search(String * folder, IMAPSearchKind kind, String * searchString, ErrorCode * pError) { IMAPSearchExpression * expr; |