Skip to content

Commit 1d8df4a

Browse files
committed
eml2mt: add option to extract just an attachment embedded message
1 parent c4d30fc commit 1d8df4a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

doc/gromox-eml2mt.8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ data stream should be consumed by an mt2exm invocation on the \fIsame\fP Gromox
3535
cluster.
3636
.SH Options
3737
.TP
38+
\fB\-\-decap\fP=\fIn\fP
39+
Once a MAPI message object is constructed, select attachment number \fIn\fP's
40+
embedded message as the "top-level" message and discard the rest of the outer
41+
message. \fIn\fP is 1-based.
42+
.TP
3843
\fB\-\-ical\fP
3944
Treat all file arguments as iCalendar input. This is the default if the program
4045
was invoked as gromox\-ical2mt. Messages will be anchored to the calendar

tools/eml2mt.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: AGPL-3.0-or-later
22
// SPDX-FileCopyrightText: 2023–2025 grommunio GmbH
33
// This file is part of Gromox.
4+
#include <algorithm>
45
#include <cstdint>
56
#include <cstdio>
67
#include <cstdlib>
@@ -44,11 +45,12 @@ enum {
4445
};
4546

4647
static unsigned int g_import_mode = IMPORT_MAIL;
47-
static unsigned int g_oneoff;
48+
static unsigned int g_oneoff, g_attach_decap;
4849
static constexpr HXoption g_options_table[] = {
4950
{nullptr, 'P', HXTYPE_NONE, &g_oxvcard_pedantic, nullptr, nullptr, 0, "Enable pedantic import mode"},
5051
{nullptr, 'p', HXTYPE_NONE | HXOPT_INC, &g_show_props, nullptr, nullptr, 0, "Show properties in detail (if -t)"},
5152
{nullptr, 't', HXTYPE_NONE, &g_show_tree, nullptr, nullptr, 0, "Show tree-based analysis of the archive"},
53+
{"decap", 0, HXTYPE_UINT, &g_attach_decap, {}, {}, {}, "Decapsulate embedded message (1-based index)", "IDX"},
5254
{"ical", 0, HXTYPE_VAL, &g_import_mode, nullptr, nullptr, IMPORT_ICAL, "Treat input as iCalendar"},
5355
{"mail", 0, HXTYPE_VAL, &g_import_mode, nullptr, nullptr, IMPORT_MAIL, "Treat input as Internet Mail"},
5456
{"mbox", 0, HXTYPE_VAL, &g_import_mode, {}, {}, IMPORT_MBOX, "Treat input as Unix mbox"},
@@ -365,6 +367,17 @@ int main(int argc, char **argv) try
365367
continue;
366368
}
367369
}
370+
if (g_attach_decap > 0) {
371+
auto osize = msgs.size();
372+
for (auto &msg : msgs) {
373+
auto ret = gi_decapsulate_attachment(msg, g_attach_decap - 1);
374+
if (ret != 0)
375+
msg.reset();
376+
}
377+
std::erase_if(msgs, [](const message_ptr &x) { return x == nullptr; });
378+
fprintf(stderr, "Attachment decapsulation filter: %zu MAPI messages have been turned into %zu\n",
379+
osize, msgs.size());
380+
}
368381

369382
if (HXio_fullwrite(STDOUT_FILENO, "GXMT0003", 8) < 0)
370383
throw YError("PG-1014: %s", strerror(errno));

0 commit comments

Comments
 (0)