diff options
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; |