Skip to content

Commit

Permalink
Merge branch 'prime'
Browse files Browse the repository at this point in the history
  • Loading branch information
jengelh committed Jul 10, 2024
2 parents 5c0959b + fe6a029 commit 3387e02
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 10 deletions.
16 changes: 16 additions & 0 deletions doc/gromox-exm2eml.8
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,21 @@ that particular folder.
.PP
An alternate way to get an EML representation is using grommunio-web's "Export
as > EML file(s)" function from the context menu of a mail item.
.SH Options
.TP
\fB\-Y\fP \fIvalue\fP
If set to 1, allday events are emitted as so-called floating dates.
If set to 0 however, allday events are emitted as precise-time events.
.br
Default: 1
\fB\-p\fP
Show properties in detail (enhances \fB\-t\fP).
.TP
\fB\-t\fP
Show a diagnostic tree view of the source data as it is being read.
.TP
\fB\-u\fP [\fIuser\fP]\fB@\fIdomin.example\fP
Source mail store from which to load the message from. For the public folder of
a domain, leave out the local part, i.e. use \fB@\fP\fIdomain.example\fP.
.SH See also
\fBgromox\fP(7), \fBgromox\-eml2mt\fP(8gx)
3 changes: 3 additions & 0 deletions doc/gromox-mt2exm.8
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ Print folder/message summary as these items are processed.
Target mail store which to import mails to. For the public folder of a domain,
leave out the local part, i.e. use \fB@\fP\fIdomain.example\fP.
.TP
\fB\-v\fP
Verbose mode: report individual FID/MIDs for newly created objects.
.TP
\fB\-x\fP
When importing an MT stream that does not request message splicing, mt2exm will
raise an error if a to-be-created folder already exists. This behavior can be
Expand Down
21 changes: 18 additions & 3 deletions lib/mapi/oxvcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ unsigned int g_oxvcard_pedantic;
static constexpr uint32_t g_n_proptags[] =
{PR_SURNAME, PR_GIVEN_NAME, PR_MIDDLE_NAME,
PR_DISPLAY_NAME_PREFIX, PR_GENERATION};
/* The 8000s numbers must match up with the order of the oxvcard_get_propids::bf array */
static constexpr uint32_t g_workaddr_proptags[] =
{0x8000001F, 0x8001001F, 0x8002001F, 0x8003001F, 0x8004001F, 0x8005001F};
static constexpr uint32_t g_homeaddr_proptags[] =
Expand All @@ -56,6 +57,8 @@ static constexpr uint32_t g_otheraddr_proptags[] =
PR_OTHER_ADDRESS_POSTAL_CODE, PR_OTHER_ADDRESS_COUNTRY};
static constexpr uint32_t g_email_proptags[] =
{0x8006001F, 0x8007001F, 0x8008001F};
static constexpr uint32_t g_addrtype_proptags[] =
{0x8012001F, 0x8013001F, 0x8014001F};
static constexpr uint32_t g_im_proptag = 0x8009001F;
static constexpr uint32_t g_categories_proptag = 0x800A101F;
static constexpr uint32_t g_bcd_proptag = 0x800B0102;
Expand Down Expand Up @@ -87,9 +90,10 @@ static BOOL oxvcard_check_compatible(const vcard *pvcard)
static BOOL oxvcard_get_propids(PROPID_ARRAY *ppropids,
GET_PROPIDS get_propids)
{
PROPERTY_NAME bf[18];
PROPERTY_NAME bf[21];
size_t start = 0, z = 0;


/* bf array must be ordered w.r.t. g_workaddr_proptags et al */
bf[z++].lid = PidLidWorkAddressPostOfficeBox;
bf[z++].lid = PidLidWorkAddressStreet;
bf[z++].lid = PidLidWorkAddressCity;
Expand Down Expand Up @@ -126,6 +130,16 @@ static BOOL oxvcard_get_propids(PROPID_ARRAY *ppropids,
bf[z].kind = MNID_STRING;
bf[z++].pname = deconst("vcarduid");

bf[z].guid = PSETID_ADDRESS;
bf[z].kind = MNID_ID;
bf[z++].lid = PidLidEmail1AddressType;
bf[z].guid = PSETID_ADDRESS;
bf[z].kind = MNID_ID;
bf[z++].lid = PidLidEmail2AddressType;
bf[z].guid = PSETID_ADDRESS;
bf[z].kind = MNID_ID;
bf[z++].lid = PidLidEmail3AddressType;

PROPNAME_ARRAY propnames;
propnames.count = z;
propnames.ppropname = bf;
Expand Down Expand Up @@ -401,7 +415,8 @@ message_content *oxvcard_import(const vcard *pvcard, GET_PROPIDS get_propids) tr
continue;
if (mail_count > 2)
continue;
if (pmsg->proplist.set(g_email_proptags[mail_count++], pstring) != 0)
if (pmsg->proplist.set(g_email_proptags[mail_count], pstring) != 0 ||
pmsg->proplist.set(g_addrtype_proptags[mail_count++], "SMTP") != 0)
return imp_null;
} else if (strcasecmp(pvline_name, "TITLE") == 0) {
auto pstring = pvline->get_first_subval();
Expand Down
8 changes: 7 additions & 1 deletion tools/exm2eml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ static unsigned int g_export_mode = EXPORT_MAIL;
static int g_allday_mode = -1;
static constexpr HXoption g_options_table[] = {
{nullptr, 'Y', HXTYPE_INT, &g_allday_mode, nullptr, nullptr, 0, "Allday emission mode (default=-1, YMDHMS=0, YMD=1)"},
{nullptr, 'u', HXTYPE_STRING, &g_username, nullptr, nullptr, 0, "Username of store to import to", "EMAILADDR"},
{nullptr, 'p', HXTYPE_NONE, &g_show_props, nullptr, nullptr, 0, "Show properties in detail (if -t)"},
{nullptr, 't', HXTYPE_NONE, &g_show_tree, nullptr, nullptr, 0, "Show tree-based analysis of the archive"},
{nullptr, 'u', HXTYPE_STRING, &g_username, nullptr, nullptr, 0, "Username of store to export from", "EMAILADDR"},
{"ical", 0, HXTYPE_VAL, &g_export_mode, nullptr, nullptr, EXPORT_ICAL, "Export as calendar object"},
{"mail", 0, HXTYPE_VAL, &g_export_mode, nullptr, nullptr, EXPORT_MAIL, "Export as RFC5322 mail"},
{"mt", 0, HXTYPE_VAL, &g_export_mode, nullptr, nullptr, EXPORT_GXMT, "Export as Gromox mailbox transfer format"},
Expand Down Expand Up @@ -193,6 +195,10 @@ int main(int argc, char **argv) try
return EXIT_FAILURE;
}
}
if (g_show_tree) {
fprintf(stderr, "Message 0\n");
gi_dump_msgctnt(0, *ctnt);
}
if (g_export_mode == EXPORT_MAIL) {
if (!oxcmail_export(ctnt, false, oxcmail_body::plain_and_html,
&imail, zalloc, cu_get_propids,
Expand Down
21 changes: 16 additions & 5 deletions tools/genimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@

using namespace std::string_literals;
using namespace gromox;
using LLU = unsigned long long;
namespace exmdb_client = exmdb_client_remote;

std::string g_dstuser;
static std::string g_storedir_s;
const char *g_storedir;
unsigned int g_user_id, g_show_tree, g_show_props, g_wet_run = 1, g_public_folder;
unsigned int g_user_id, g_show_tree, g_show_props, g_wet_run = 1;
unsigned int g_public_folder, g_verbose_create;
static thread_local alloc_context g_alloc_mgr;
static ec_error_t (*exmdb_local_rules_execute)(const char *, const char *, const char *, eid_t, eid_t, unsigned int);

Expand Down Expand Up @@ -170,8 +172,7 @@ void gi_dump_folder_map(const gi_folder_map_t &map)
fprintf(stderr, "\t# HierID (hex) -> Target name\n");
for (const auto &[nid, tgt] : map)
fprintf(stderr, "\t%xh -> %s (%s %llxh)\n", nid, tgt.create_name.c_str(),
tgt.create ? "create under" : "splice into",
static_cast<unsigned long long>(tgt.fid_to));
tgt.create ? "create under" : "splice into", LLU{tgt.fid_to});
}

void gi_dump_name_map(const gi_name_map &map)
Expand Down Expand Up @@ -372,6 +373,9 @@ int exm_create_folder(uint64_t parent_fld, TPROPVAL_ARRAY *props, bool o_excl,
fprintf(stderr, "exm: Could not create folder \"%s\". "
"Either it already existed or some there was some other unspecified problem.\n", dn);
return -EEXIST;
} else if (g_verbose_create) {
fprintf(stderr, "exm: Created folder \"%s\" (fid=0x%llx)\n", dn,
LLU{rop_util_get_gc_value(*new_fld_id)});
}
return 0;
}
Expand All @@ -382,8 +386,7 @@ int exm_permissions(eid_t fid, const std::vector<PERMISSION_DATA> &perms)
return 0;
if (!exmdb_client::update_folder_permission(g_storedir, fid, false,
perms.size(), perms.data())) {
fprintf(stderr, "exm: update_folder_perm(%llxh) RPC failed\n",
static_cast<unsigned long long>(fid));
fprintf(stderr, "exm: update_folder_perm(%llxh) RPC failed\n", LLU{fid});
return -EIO;
}
return 0;
Expand All @@ -408,6 +411,10 @@ int exm_deliver_msg(const char *target, MESSAGE_CONTENT *ct, unsigned int mode)
auto dm_status = static_cast<deliver_message_result>(r32);
switch (dm_status) {
case deliver_message_result::result_ok:
if (g_verbose_create)
fprintf(stderr, "Created/delivered new message 0x%llx:0x%llx\n",
LLU{rop_util_get_gc_value(folder_id)},
LLU{rop_util_get_gc_value(msg_id)});
break;
case deliver_message_result::result_error:
fprintf(stderr, "Message rejected - unspecified reason\n");
Expand Down Expand Up @@ -498,6 +505,10 @@ int exm_create_msg(uint64_t parent_fld, MESSAGE_CONTENT *ctnt)
} else if (e_result != ecSuccess) {
fprintf(stderr, "exm: write_message: %s\n", mapi_strerror(e_result));
return -EIO;
} else if (g_verbose_create) {
fprintf(stderr, "Created new message 0x%llx:0x%llx\n",
LLU{rop_util_get_gc_value(parent_fld)},
LLU{rop_util_get_gc_value(msg_id)});
}
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion tools/genimport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ enum {

extern std::string g_dstuser;
extern const char *g_storedir;
extern unsigned int g_user_id, g_show_tree, g_show_props, g_wet_run, g_public_folder;
extern unsigned int g_user_id, g_show_tree, g_show_props, g_wet_run;
extern unsigned int g_public_folder, g_verbose_create;

extern void tree(unsigned int d);
extern void tlog(const char *f, ...) __attribute__((format(printf, 1, 2)));
Expand Down
1 change: 1 addition & 0 deletions tools/mt2exm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static constexpr HXoption g_options_table[] = {
{nullptr, 'p', HXTYPE_NONE, &g_show_props, nullptr, nullptr, 0, "Show properties in detail (if -t)"},
{nullptr, 't', HXTYPE_NONE, &g_show_tree, nullptr, nullptr, 0, "Show tree-based analysis of the archive"},
{nullptr, 'u', HXTYPE_STRING, &g_username, nullptr, nullptr, 0, "Username of store to import to", "EMAILADDR"},
{nullptr, 'v', HXTYPE_NONE | HXOPT_INC, &g_verbose_create, nullptr, nullptr, 0, "Be more verbose"},
{nullptr, 'x', HXTYPE_VAL, &g_oexcl, nullptr, nullptr, 0, "Disable O_EXCL like behavior for non-spliced folders"},
{"repeat", 0, HXTYPE_UINT, &g_repeat_iter, {}, {}, 0, "For testing purposes, import each message N times", "N"},
{"skip-notif", 0, HXTYPE_NONE, &g_skip_notif, nullptr, nullptr, 0, "Skip emission of notifications (if -D)"},
Expand Down

0 comments on commit 3387e02

Please sign in to comment.