Skip to content

Commit

Permalink
append.c: add username and accountId to annotator dlist
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmurchison authored and rjbs committed Sep 18, 2024
1 parent c75865d commit bb39157
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions imap/append.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ static int callout_run_executable(const char *callout,
*/
static void callout_encode_args(struct buf *args,
const char *fname,
const char *username,
const char *accountid,
const struct body *body,
struct entryattlist *annotations,
strarray_t *flags)
Expand All @@ -607,6 +609,12 @@ static void callout_encode_args(struct buf *args,
buf_printf(args, "FILENAME ");
message_write_nstring(args, fname);

buf_printf(args, " USERNAME ");
message_write_nstring(args, username);

buf_printf(args, " ACCOUNTID ");
message_write_nstring(args, accountid);

buf_printf(args, " ANNOTATIONS (");
for (ee = annotations ; ee ; ee = ee->next) {
struct attvaluelist *av;
Expand Down Expand Up @@ -742,6 +750,8 @@ static void callout_decode_results(const char *callout,
}

static int callout_run(const char *fname,
const char *username,
const char *accountid,
const struct body *body,
struct entryattlist **user_annots,
struct entryattlist **system_annots,
Expand All @@ -757,7 +767,8 @@ static int callout_run(const char *fname,
assert(callout);
assert(flags);

callout_encode_args(&args, fname, body, *user_annots, flags);
callout_encode_args(&args, fname, username, accountid,
body, *user_annots, flags);

if (stat(callout, &sb) < 0) {
syslog(LOG_ERR, "cannot stat annotation_callout %s: %m", callout);
Expand Down Expand Up @@ -1108,11 +1119,16 @@ EXPORTED int append_fromstage_full(struct appendstate *as, struct body **body,
}

if (config_getstring(IMAPOPT_ANNOTATION_CALLOUT)) {
char *owner = mboxname_to_userid(mailbox_name(as->mailbox));
const char *userid = as->userid;

if (flags)
newflags = strarray_dup(flags);
else
newflags = strarray_new();
r = callout_run(fname, *body, &user_annots, &system_annots, newflags);
r = callout_run(fname, userid, owner,
*body, &user_annots, &system_annots, newflags);
free(owner);
if (r) {
syslog(LOG_ERR, "Annotation callout failed, ignoring");
r = 0;
Expand Down Expand Up @@ -1374,7 +1390,11 @@ HIDDEN int append_run_annotator(struct appendstate *as,
fclose(f);
f = NULL;

r = callout_run(fname, body, &user_annots, &system_annots, flags);
char *owner = mboxname_to_userid(mailbox_name(as->mailbox));
const char *userid = as->userid;
r = callout_run(fname, userid, owner,
body, &user_annots, &system_annots, flags);
free(owner);
if (r) goto out;

/* Reset system flags */
Expand Down

0 comments on commit bb39157

Please sign in to comment.