@@ -684,6 +684,42 @@ void EWSContext::enableEventStream(int timeout)
684684 m_notify = std::make_unique<NotificationContext>(expire);
685685}
686686
687+ /* *
688+ * @brief Export message content to string
689+ *
690+ * @param dir Parent store
691+ * @param content Content to export
692+ * @param log_id Log ID
693+ *
694+ * @return Serialized content
695+ */
696+ std::string EWSContext::exportContent (const std::string& dir, const MESSAGE_CONTENT& content, const std::string& log_id) const
697+ {
698+ MAIL mail;
699+ auto getPropIds = [&](const PROPNAME_ARRAY *names, PROPID_ARRAY *ids)
700+ { *ids = getNamedPropIds (dir, *names); return TRUE ; };
701+ auto getPropName = [&](uint16_t id, PROPERTY_NAME **name) { *name = getPropertyName (dir, id); return TRUE ; };
702+ if (!oxcmail_export (&content, log_id.c_str (), false ,
703+ oxcmail_body::plain_and_html, &mail, alloc, getPropIds, getPropName))
704+ throw EWSError::ItemCorrupt (E3072 );
705+ auto mail_len = mail.get_length ();
706+ if (mail_len < 0 )
707+ throw EWSError::ItemCorrupt (E3073 );
708+ STREAM tempStream;
709+ if (!mail.serialize (&tempStream))
710+ throw EWSError::ItemCorrupt (E3074 );
711+ std::string mime;
712+ mime.reserve (mail_len);
713+ char *data;
714+ unsigned int size = STREAM_BLOCK_SIZE;
715+ while ((data = static_cast <char *>(tempStream.get_read_buf (&size))) != nullptr ) {
716+ mime.insert (mime.end (), data, &data[size]);
717+ size = STREAM_BLOCK_SIZE;
718+ }
719+ return mime;
720+ }
721+
722+
687723/* *
688724 * @brief Get user or domain ID by name
689725 *
@@ -1101,7 +1137,19 @@ sAttachment EWSContext::loadAttachment(const std::string& dir, const sAttachment
11011137 PROPTAG_ARRAY tags{std::size (tagIDs), tagIDs};
11021138 if (!m_plugin.exmdb .get_instance_properties (dir.c_str (), 0 , aInst->instanceId , &tags, &props))
11031139 throw DispatchError (E3083 );
1104- return tAttachment::create (aid, props);
1140+ sShape shape (props);
1141+
1142+ auto method = props.get <const uint32_t >(PR_ATTACH_METHOD);
1143+ if (method != nullptr && *method == ATTACH_EMBEDDED_MSG) {
1144+ auto eInst = m_plugin.loadEmbeddedInstance (dir, aInst->instanceId );
1145+ MESSAGE_CONTENT content{};
1146+ if (!m_plugin.exmdb .read_message_instance (dir.c_str (),
1147+ eInst->instanceId , &content))
1148+ throw DispatchError (E3208 );
1149+ auto log_id = dir + " :a" + std::to_string (aid.attachment_num );
1150+ shape.mimeContent .emplace (exportContent (dir, content, log_id));
1151+ }
1152+ return tAttachment::create (aid, std::move (shape));
11051153}
11061154
11071155/* *
@@ -1232,33 +1280,12 @@ void EWSContext::loadSpecial(const std::string& dir, uint64_t fid, uint64_t mid,
12321280 if (!exmdb.read_message (dir.c_str (), nullptr , CP_ACP, mid, &content) ||
12331281 content == nullptr )
12341282 throw EWSError::ItemNotFound (E3071 );
1235- MAIL mail;
1236- auto getPropIds = [&](const PROPNAME_ARRAY* names, PROPID_ARRAY* ids)
1237- {*ids = getNamedPropIds (dir, *names); return TRUE ;};
1238- auto getPropName = [&](uint16_t id, PROPERTY_NAME** name)
1239- {*name = getPropertyName (dir, id); return TRUE ;};
12401283 auto log_id = dir + " :m" + std::to_string (mid);
1241- if (!oxcmail_export (content, log_id.c_str (), false ,
1242- oxcmail_body::plain_and_html, &mail, alloc, getPropIds, getPropName))
1243- throw EWSError::ItemCorrupt (E3072 );
1244- auto mailLen = mail.get_length ();
1245- if (mailLen < 0 )
1246- throw EWSError::ItemCorrupt (E3073 );
1247- STREAM tempStream;
1248- if (!mail.serialize (&tempStream))
1249- throw EWSError::ItemCorrupt (E3074 );
1250- auto & mimeContent = item.MimeContent .emplace ();
1251- mimeContent.reserve (mailLen);
1252- uint8_t * data;
1253- unsigned int size = STREAM_BLOCK_SIZE;
1254- while ((data = static_cast <uint8_t *>(tempStream.get_read_buf (&size))) != nullptr ) {
1255- mimeContent.insert (mimeContent.end (), data, data + size);
1256- size = STREAM_BLOCK_SIZE;
1257- }
1284+ item.MimeContent .emplace (exportContent (dir, *content, log_id));
12581285 }
12591286 if (special & sShape ::Attachments) {
12601287 static uint32_t tagIDs[] = {PR_ATTACH_METHOD, PR_DISPLAY_NAME, PR_ATTACH_MIME_TAG, PR_ATTACH_CONTENT_ID,
1261- PR_ATTACH_LONG_FILENAME, PR_ATTACHMENT_FLAGS};
1288+ PR_ATTACH_LONG_FILENAME, PR_ATTACHMENT_FLAGS, PR_ATTACH_SIZE };
12621289 auto mInst = m_plugin.loadMessageInstance (dir, fid, mid);
12631290 uint16_t count;
12641291 if (!exmdb.get_message_instance_attachments_num (dir.c_str (), mInst ->instanceId , &count))
@@ -1272,7 +1299,7 @@ void EWSContext::loadSpecial(const std::string& dir, uint64_t fid, uint64_t mid,
12721299 if (!exmdb.get_instance_properties (dir.c_str (), 0 , aInst->instanceId , &tags, &props))
12731300 throw DispatchError (E3080 );
12741301 aid.attachment_num = i;
1275- item.Attachments ->emplace_back (tAttachment::create (aid, props));
1302+ item.Attachments ->emplace_back (tAttachment::create (aid, sShape ( props) ));
12761303 }
12771304 }
12781305 if (special & sShape ::Rights)
0 commit comments