Skip to content

Conversation

@wu0lss4j
Copy link

On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
modified: imap-common.c

modified lines 1153 and 1188 adding UID FETCH instead of just FETCH, hopefully now fdm will get all of gmail's special headers like X-GM-LABELS, X-GM-THRID, and X-GM-MSGID

removed one UID FETCH because the return msg apparently the IMAP server does not reply UID FETCH rather just FETCH

added the necessary logic to locate the " UID {UID}" at the end of the IMAP server's reply to the UID FETCH instruction, correctly assuming that everything that is in the message between X-GM-LABELS and UID are the labels, it even checks for the special case where there are no gmail labels.

Note: Gmail is extra special with labels, because if you tell fdm to fetch all email from a single label, that label is not returned by gmail and fdm will never see it. This is because gmail treats labels as virtual folders.

Not happy with the code, and I think it can be further improved, it's still quite fast, and I've yet to find another edge case with labels. So far so good.

modified:   configure.ac

added version info, but somehow doesn't stick, I wanted to call this program fdm_i 2.2i_1 but ¯_(ツ)_/¯, it ain't workin...

 On branch master
 Your branch is up to date with 'origin/master'.

 Changes to be committed:
	modified:   imap-common.c

modified lines 1153 and 1188 adding UID FETCH instead of just FETCH,
hopefully now fdm will get all of gmail's special headers like
X-GM-LABELS, X-GM-THRID, and X-GM-MSGID

removed one UID FETCH because the return msg apparently the IMAP server
does not reply UID FETCH rather just FETCH

added the necessary logic to locate the " UID {UID}" at the end of the
IMAP server's reply to the UID FETCH instruction, correctly assuming
that everything that is in the message between X-GM-LABELS and UID are
the labels, it even checks for the special case where there are no gmail
labels.

Note: Gmail is extra special with labels, because if you tell fdm to
fetch all email from a single label, that label is not returned by gmail
and fdm will never see it. This is because gmail treats labels as
virtual folders.

Not happy with the code, and I think it can be further improved, it's
still quite fast, and I've yet to find another edge case with labels. So
far so good.

	modified:   configure.ac

added version info, but somehow doesn't stick, I wanted to call this
program fdm_i 2.2i_1 but ¯\_(ツ)_/¯, it ain't workin...
@nicm
Copy link
Owner

nicm commented Oct 20, 2025

This seems more complicated than necessary, you just need to skip everything after the ) which closes the X-GM-LABELS, no? So couldn't you just find that ), something like:

@@ -1193,10 +1193,9 @@ imap_state_gmext_body(struct account *a, struct fetch_ctx *fctx)
        if ((lb = strchr(lb, '(')) == NULL)
                return (imap_invalid(a, line));
        lb++; /* drop '(' */
-       lblen = strlen(lb);
-       if (lblen < 2 || lb[lblen - 1] != ')' || lb[lblen - 2] != ')')
+       if ((br = strchr(lb, ')') == NULL)
                return (imap_invalid(a, line));
-       lblen -= 2; /* drop '))' from the end */
+       lblen = br - lb;

        add_tag(&m->tags, "gmail_msgid", "%llu", msgid);
        add_tag(&m->tags, "gmail_thrid", "%llu", thrid);

@nicm
Copy link
Owner

nicm commented Oct 20, 2025

Or maybe the labels can contain )s?

@wu0lss4j
Copy link
Author

wu0lss4j commented Oct 20, 2025 via email

@wu0lss4j
Copy link
Author

wu0lss4j commented Oct 20, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants