Skip to content

Commit 5f8dbb8

Browse files
committed
tools: define and use GXMT v4 stream format for import/export
eml2mt needs a way to convey a RFC5322 Internet Message to mt2exm. Enhance the GXMT stream format used between tools to accomodate such. References: GXH-155, GXF-2229
1 parent 847fde6 commit 5f8dbb8

File tree

9 files changed

+37
-17
lines changed

9 files changed

+37
-17
lines changed

doc/mtformat.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Spec
1818

1919
All integers are to be in little-endian form.
2020

21-
* ``char magic[8] = "GXMT0003";``
21+
* ``char magic[8] = "GXMT0004";``
2222
Magic fixed value to indicate the MT stream revision.
2323
* ``uint32_t splice_flag;``
2424
Indicates whether the root object of this MT stream is to become a new folder
@@ -101,6 +101,8 @@ to create folders/messages in the target mailbox. Each packet/frame is:
101101
* PERMISSION_DATA serialized struct
102102
* For objtype MAPI_MESSAGE:
103103
* MESSAGE_CONTENT serialized struct
104+
* NUL-terminated string for the RFC5322 representation
105+
* NUL-terminated string (reserved)
104106
* For objtype 250 (named property):
105107
* PROPERTY_NAME serialized struct
106108
* For other object types:

tools/edb2mt.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ static void do_folder(mbox_state &mbs, const edb_folder &folder)
538538
*/
539539
static errno_t do_mbox(mbox_state &mbs)
540540
{
541-
if (HXio_fullwrite(STDOUT_FILENO, "GXMT0003", 8) < 0)
541+
if (HXio_fullwrite(STDOUT_FILENO, "GXMT0004", 8) < 0)
542542
throw YError("PG-1014: %s", strerror(errno));
543543
uint8_t flag = false;
544544
if (HXio_fullwrite(STDOUT_FILENO, &flag, sizeof(flag)) < 0) /* splice flag */
@@ -629,7 +629,9 @@ static errno_t do_file(const char *filename) try
629629
ep.p_uint32(1) != pack_result::ok ||
630630
ep.p_uint32(static_cast<uint32_t>(parent.type)) != pack_result::ok ||
631631
ep.p_uint64(parent.folder_id) != pack_result::ok ||
632-
ep.p_msgctnt(*ctnt) != pack_result::ok) {
632+
ep.p_msgctnt(*ctnt) != pack_result::ok ||
633+
ep.p_str("") != pack_result::ok ||
634+
ep.p_str("") != pack_result::ok) {
633635
fprintf(stderr, "E-2021\n");
634636
return EXIT_FAILURE;
635637
}

tools/eml2mt.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,9 @@ int main(int argc, char **argv) try
410410
ep.p_uint32(i + 1) != pack_result::ok ||
411411
ep.p_uint32(static_cast<uint32_t>(parent.type)) != pack_result::ok ||
412412
ep.p_uint64(parent.folder_id) != pack_result::ok ||
413-
ep.p_msgctnt(*msgs[i]) != pack_result::ok) {
413+
ep.p_msgctnt(*msgs[i]) != pack_result::ok ||
414+
ep.p_str("") != pack_result::ok ||
415+
ep.p_str("") != pack_result::ok) {
414416
fprintf(stderr, "E-2004\n");
415417
return EXIT_FAILURE;
416418
}

tools/exm2eml.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ int main(int argc, char **argv) try
236236
if (p.kind <= MNID_STRING)
237237
static_namedprop_map.emplace(tags[i], p);
238238
}
239-
if (HXio_fullwrite(STDOUT_FILENO, "GXMT0003", 8) < 0)
239+
if (HXio_fullwrite(STDOUT_FILENO, "GXMT0004", 8) < 0)
240240
throw YError("PG-1014: %s", strerror(errno));
241241
uint8_t flag = false;
242242
if (HXio_fullwrite(STDOUT_FILENO, &flag, sizeof(flag)) < 0) /* splice flag */
@@ -253,7 +253,9 @@ int main(int argc, char **argv) try
253253
ep.p_uint32(msg_id) != pack_result::ok ||
254254
ep.p_uint32(static_cast<uint32_t>(0)) != pack_result::ok ||
255255
ep.p_uint64(MAILBOX_FID_UNANCHORED) != pack_result::ok ||
256-
ep.p_msgctnt(*ctnt) != pack_result::ok) {
256+
ep.p_msgctnt(*ctnt) != pack_result::ok ||
257+
ep.p_str("") != pack_result::ok ||
258+
ep.p_str("") != pack_result::ok) {
257259
fprintf(stderr, "E-2005\n");
258260
return EXIT_FAILURE;
259261
}

tools/genimport.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
enum {
1515
GXMT_FOLDER = static_cast<unsigned int>(MAPI_FOLDER),
1616
GXMT_MESSAGE = static_cast<unsigned int>(MAPI_MESSAGE),
17-
GXMT_NAMEDPROP = 250,
17+
GXMT_NAMEDPROP = 250U,
1818
};
1919

2020
struct PERMISSION_DATA;

tools/kdb2mt.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,9 @@ static int do_message(driver &drv, unsigned int depth, const parent_desc &parent
11961196
ep.p_uint32(item.m_hid) != pack_result::ok ||
11971197
ep.p_uint32(static_cast<uint32_t>(parent.type)) != pack_result::ok ||
11981198
ep.p_uint64(parent.folder_id) != pack_result::ok ||
1199-
ep.p_msgctnt(*ctnt) != pack_result::ok)
1199+
ep.p_msgctnt(*ctnt) != pack_result::ok ||
1200+
ep.p_str("") != pack_result::ok ||
1201+
ep.p_str("") != pack_result::ok)
12001202
throw YError("PF-1058");
12011203
uint64_t xsize = cpu_to_le64(ep.m_offset);
12021204
if (HXio_fullwrite(STDOUT_FILENO, &xsize, sizeof(xsize)) < 0)
@@ -1375,7 +1377,7 @@ static int do_item(driver &drv, unsigned int depth, const parent_desc &parent, k
13751377
static int do_database(std::unique_ptr<driver> &&drv, const char *title)
13761378
{
13771379
uint8_t xsplice = g_splice;
1378-
if (HXio_fullwrite(STDOUT_FILENO, "GXMT0003", 8) < 0)
1380+
if (HXio_fullwrite(STDOUT_FILENO, "GXMT0004", 8) < 0)
13791381
throw YError("PK-1032: %s", strerror(errno));
13801382
if (HXio_fullwrite(STDOUT_FILENO, &xsplice, sizeof(xsplice)) < 0)
13811383
throw YError("PK-1034: %s", strerror(errno));

tools/mt2exm.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static int exm_read_base_maps()
9797
return 0;
9898
if (ret < 0 || static_cast<size_t>(ret) != std::size(magic))
9999
throw YError("PG-1126: %s", strerror_eof(errno));
100-
if (memcmp(magic, "GXMT0003", 8) != 0)
100+
if (memcmp(magic, "GXMT0004", 8) != 0)
101101
throw YError("PG-1127: Unrecognized input format");
102102
ret = HXio_fullread(STDIN_FILENO, &g_splice, sizeof(g_splice));
103103
if (ret < 0 || static_cast<size_t>(ret) != sizeof(g_splice))
@@ -301,7 +301,8 @@ static int exm_folder(const ob_desc &obd, TPROPVAL_ARRAY &props,
301301
return 0;
302302
}
303303

304-
static int exm_message(const ob_desc &obd, MESSAGE_CONTENT &ctnt)
304+
static int exm_message(const ob_desc &obd, MESSAGE_CONTENT &ctnt,
305+
const std::string &im_std)
305306
{
306307
if (g_show_tree)
307308
printf("exm: Message %lxh (parent=%llxh)\n",
@@ -408,7 +409,12 @@ static int exm_packet(const void *buf, size_t bufsize)
408409
auto cl_0 = HX::make_scope_exit([&]() { message_content_free_internal(&ctnt); });
409410
if (ep.g_msgctnt(&ctnt) != pack_result::ok)
410411
throw YError("PG-1119");
411-
return exm_message(obd, ctnt);
412+
std::string im_std, reserved;
413+
if (ep.g_str(&im_std) != pack_result::ok ||
414+
ep.g_str(&reserved) != pack_result::ok)
415+
throw YError("PG-1113");
416+
reserved = {};
417+
return exm_message(obd, ctnt, im_std);
412418
}
413419
throw YError("PG-1117: unknown obd.mapitype %u", static_cast<unsigned int>(obd.mapitype));
414420
}

tools/oxm2mt.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ static errno_t do_file(const char *filename) try
583583
return ret;
584584
}
585585

586-
if (HXio_fullwrite(STDOUT_FILENO, "GXMT0003", 8) < 0)
586+
if (HXio_fullwrite(STDOUT_FILENO, "GXMT0004", 8) < 0)
587587
throw YError("PG-1014: %s", strerror(errno));
588588
uint8_t flag = false;
589589
if (HXio_fullwrite(STDOUT_FILENO, &flag, sizeof(flag)) < 0) /* splice flag */
@@ -612,7 +612,9 @@ static errno_t do_file(const char *filename) try
612612
ep.p_uint32(1) != pack_result::ok ||
613613
ep.p_uint32(static_cast<uint32_t>(parent.type)) != pack_result::ok ||
614614
ep.p_uint64(parent.folder_id) != pack_result::ok ||
615-
ep.p_msgctnt(*ctnt) != pack_result::ok) {
615+
ep.p_msgctnt(*ctnt) != pack_result::ok ||
616+
ep.p_str("") != pack_result::ok ||
617+
ep.p_str("") != pack_result::ok) {
616618
fprintf(stderr, "E-2006\n");
617619
return EXIT_FAILURE;
618620
}

tools/pff2mt.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,9 @@ static int do_message(unsigned int depth, const parent_desc &parent,
936936
ep.p_uint32(ident) != pack_result::ok ||
937937
ep.p_uint32(static_cast<uint32_t>(parent.type)) != pack_result::ok ||
938938
ep.p_uint64(parent.folder_id) != pack_result::ok ||
939-
ep.p_msgctnt(*ctnt) != pack_result::ok)
939+
ep.p_msgctnt(*ctnt) != pack_result::ok ||
940+
ep.p_str("") != pack_result::ok ||
941+
ep.p_str("") != pack_result::ok)
940942
throw YError("PF-1058");
941943
uint64_t xsize = cpu_to_le64(ep.m_offset);
942944
if (HXio_fullwrite(STDOUT_FILENO, &xsize, sizeof(xsize)) < 0)
@@ -1207,7 +1209,7 @@ static errno_t do_file(const char *filename) try
12071209
}
12081210

12091211
uint8_t xsplice = g_splice;
1210-
if (HXio_fullwrite(STDOUT_FILENO, "GXMT0003", 8) < 0)
1212+
if (HXio_fullwrite(STDOUT_FILENO, "GXMT0004", 8) < 0)
12111213
throw YError("PF-1132: %s", strerror(errno));
12121214
if (HXio_fullwrite(STDOUT_FILENO, &xsplice, sizeof(xsplice)) < 0)
12131215
throw YError("PF-1133: %s", strerror(errno));
@@ -1233,7 +1235,7 @@ static errno_t do_file(const char *filename) try
12331235
libpff_item_ptr root;
12341236
if (libpff_file_get_root_item(file.get(), &~unique_tie(root), &~unique_tie(err)) < 1)
12351237
throw az_error("PF-1025", err);
1236-
gi_name_map_write({}); /* required by GXMT0003 format */
1238+
gi_name_map_write({}); /* required by GXMT format */
12371239

12381240
if (g_show_tree)
12391241
fprintf(stderr, "Object tree:\n");

0 commit comments

Comments
 (0)