|
1 | 1 | // SPDX-License-Identifier: AGPL-3.0-or-later |
2 | 2 | // SPDX-FileCopyrightText: 2023–2025 grommunio GmbH |
3 | 3 | // This file is part of Gromox. |
| 4 | +#include <algorithm> |
4 | 5 | #include <cstdint> |
5 | 6 | #include <cstdio> |
6 | 7 | #include <cstdlib> |
@@ -44,11 +45,12 @@ enum { |
44 | 45 | }; |
45 | 46 |
|
46 | 47 | static unsigned int g_import_mode = IMPORT_MAIL; |
47 | | -static unsigned int g_oneoff; |
| 48 | +static unsigned int g_oneoff, g_attach_decap; |
48 | 49 | static constexpr HXoption g_options_table[] = { |
49 | 50 | {nullptr, 'P', HXTYPE_NONE, &g_oxvcard_pedantic, nullptr, nullptr, 0, "Enable pedantic import mode"}, |
50 | 51 | {nullptr, 'p', HXTYPE_NONE | HXOPT_INC, &g_show_props, nullptr, nullptr, 0, "Show properties in detail (if -t)"}, |
51 | 52 | {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"}, |
52 | 54 | {"ical", 0, HXTYPE_VAL, &g_import_mode, nullptr, nullptr, IMPORT_ICAL, "Treat input as iCalendar"}, |
53 | 55 | {"mail", 0, HXTYPE_VAL, &g_import_mode, nullptr, nullptr, IMPORT_MAIL, "Treat input as Internet Mail"}, |
54 | 56 | {"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 |
365 | 367 | continue; |
366 | 368 | } |
367 | 369 | } |
| 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 | + } |
368 | 381 |
|
369 | 382 | if (HXio_fullwrite(STDOUT_FILENO, "GXMT0003", 8) < 0) |
370 | 383 | throw YError("PG-1014: %s", strerror(errno)); |
|
0 commit comments