Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Keywords for several mails at once- #12

Open
jrse opened this issue Apr 29, 2019 · 7 comments
Open

Set Keywords for several mails at once- #12

jrse opened this issue Apr 29, 2019 · 7 comments
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@jrse
Copy link
Contributor

jrse commented Apr 29, 2019

if user selects multiple mails at one "e.g. via thunderbird" and sets / deletes a keyword. the notification plugin sends the following msg.

{"user":"sm@sm.test","mailbox":"INBOX","event":"FlagsClear","uidvalidity":1556548880,"uid":1,"keywords":["x.travel",".travel","x.travel","x.travel","x.travel","x.travel","x.travel","x.travel","x.travel","travel","x.travel","x.travel","x.travel","x.travel","x.travel"]}

@jrse jrse self-assigned this Apr 29, 2019
@jrse
Copy link
Contributor Author

jrse commented Apr 29, 2019

dlog notification plugin

pr 30 00:34:47 imap(t1): Debug: Called process_msg push_notification plugin hook.
Apr 30 00:34:47 imap(t1): Debug: Message data: Mailbox [INBOX], UID [1], UIDVALIDITY [1556552541]
Apr 30 00:34:47 imap(t1): Debug: FlagsSet: Keyword set [smf.abcdfffff]
Apr 30 00:34:47 imap(t1): Debug: FlagsSet: Keyword set [smf.abcdfffff]
Apr 30 00:34:47 imap(t1): Debug: FlagsSet: Keyword set [smf.abcdfffff]
Apr 30 00:34:47 imap(t1): Debug: Called end_txn push_notification plugin hook.

@jrse
Copy link
Contributor Author

jrse commented Apr 29, 2019

keywords are set in: src/plugins/push-notification/push-notification-event-flagsset.c

./src/plugins/push-notification/push-notification-triggers.c

@jrse
Copy link
Contributor Author

jrse commented Apr 29, 2019

static void push_notification_event_flagsset_keywords_event(
struct push_notification_txn *ptxn,
struct push_notification_event_config *ec,
struct push_notification_txn_msg *msg,
struct mail *mail,
const char *const *old_keywords)
{
struct push_notification_event_flagsset_data *data;
const char *k, *const *keywords, *const *op;

data = push_notification_event_flagsset_get_data(ptxn, msg, ec);
keywords = mail_get_keywords(mail);

for (; *keywords != NULL; keywords++) {
    for (op = old_keywords; *op != NULL; op++) {
        if (strcmp(*keywords, *op) == 0) {
            break;
        }
    }

    if (*op == NULL) {
        k = p_strdup(ptxn->pool, *keywords);
        array_append(&data->keywords_set, &k, 1);
    }
}

}

@jrse jrse added bug Something isn't working question Further information is requested labels Apr 30, 2019
@jrse
Copy link
Contributor Author

jrse commented Apr 30, 2019

/src/plugins/push-notification/push-notification-txn-msg.c:
push_notification_txn_msg_end(struct push_notification_txn *ptxn,
struct mail_transaction_commit_changes *changes)

triggers the process_event notification hook, but only once!

@jrse
Copy link
Contributor Author

jrse commented Apr 30, 2019

struct push_notification_txn_msg *
push_notification_txn_msg_create(struct push_notification_txn *txn,
struct mail *mail)
-> adds the push_notification msg to the hash_table used in (push_notification_txn_msg_end)

=> this function is only called once to create the message.
the other calls deliver the created message.

@jrse
Copy link
Contributor Author

jrse commented Apr 30, 2019

looks like a bug in dovecot:

the function assumes that each message has a different txn->t->save_count, but this is not
the case. txn->t->save_count stays equal for each message.
using e.g. mail->seq as hash_table key to insert and lookup the msg, we create and process separate message for each msg.


struct push_notification_txn_msg *
push_notification_txn_msg_create(struct push_notification_txn *txn,
                                 struct mail *mail)
{
    struct push_notification_txn_msg *msg = NULL;

    if (hash_table_is_created(txn->messages)) {
        msg = hash_table_lookup(txn->messages,
                                POINTER_CAST(txn->t->save_count + 1));
        i_debug("hash table lookup called msg is %lu msg_seq = %d, uid = %d",msg,txn->t->save_count+1, mail->uid);
    } else {
        hash_table_create_direct(&txn->messages, txn->pool, 4);
    }

    if (msg == NULL) {
        msg = p_new(txn->pool, struct push_notification_txn_msg, 1);
        msg->mailbox = mailbox_get_vname(mail->box);
        /* Save sequence number - used to determine UID later. */
        msg->seq = txn->t->save_count;
        msg->uid = mail->uid;
        i_debug("adding msg uid(%d) to hash_table msg_seq = %d, mail->uid %d",msg->uid,txn->t->save_count +1, mail->uid);
        hash_table_insert(txn->messages, POINTER_CAST(txn->t->save_count + 1),
                          msg);
    }

    return msg;
}

@jrse
Copy link
Contributor Author

jrse commented Apr 30, 2019

This bug seems to be fixed in 2.3.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant