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

New emails are not marked as seen when fetched with curl #7626

Closed
orycho opened this issue Aug 25, 2021 · 27 comments
Closed

New emails are not marked as seen when fetched with curl #7626

orycho opened this issue Aug 25, 2021 · 27 comments
Labels
IMAP not-a-bug This is not a bug in curl

Comments

@orycho
Copy link

orycho commented Aug 25, 2021

I did this

I am unsing libcurl to fetch unseen emails from an account. Until curl version 7.55 (as far as I know) emails where then marked as read and where not foud again. This has changed by version 7.66 and probably still persists.

I expected the following

Emails should be marked as read once fetched

curl/libcurl version

7.66.0
[curl -V output]
Not provided. Instead, you can reproduce by using this program repeatedly on an email account with an unread email:
imap-fetch-new.c.txt

operating system

Linux kinshasa 5.9.8 #1 SMP Mon Nov 16 21:02:53 CET 2020 x86_64 x86_64 x86_64 GNU/Linux

Thanks,
Ory

@bagder bagder added the IMAP label Aug 25, 2021
@bagder
Copy link
Member

bagder commented Sep 27, 2021

I don't know what the problem is so I can't fix this. Isn't this app making curl issue a UID FETCH command? What else would curl do?

@orycho
Copy link
Author

orycho commented Sep 27, 2021 via email

@bagder
Copy link
Member

bagder commented Sep 27, 2021

You already said that in the original description. I don't know what that means. curl once used FETCH directly without UID, but it never explicitly marked anything as "read" as far as I can remember.

@orycho
Copy link
Author

orycho commented Sep 27, 2021 via email

@bagder
Copy link
Member

bagder commented Sep 27, 2021

Well, I tried to make it reproducible with the program in the attachment.

Sure, but I'm saying I don't know what the right behavior would be, IMAP wise, so I cannot fix this.

I have the hunch that the fetch request is not performed until the very end somehow?

You're getting the email, right? Then the fetch command must've been performed. Or rather the UID FETCH command to be specific.

@orycho
Copy link
Author

orycho commented Sep 27, 2021 via email

@orycho
Copy link
Author

orycho commented Sep 27, 2021 via email

@bagder
Copy link
Member

bagder commented Sep 27, 2021

In this case, it doesn't help to know what an older curl did.

@orycho
Copy link
Author

orycho commented Sep 27, 2021 via email

@bagder
Copy link
Member

bagder commented Sep 27, 2021

If I knew what the correct way would be I would not say that I don't know...

@orycho
Copy link
Author

orycho commented Sep 27, 2021 via email

@mogery
Copy link

mogery commented Oct 16, 2021

UID FETCH should automatically set the \Seen flag server-side. If you're getting any e-mails back through it, they should be marked as seen.

@mogery
Copy link

mogery commented Oct 16, 2021

7.66.0 [curl -V output] Not provided. Instead, you can reproduce by using this program repeatedly on an email account with an unread email: imap-fetch-new.c.txt

This code only issues SEARCH commands, which are not supposed to set the \Seen flag. This is correct behaviour.
If you want the \Seen flag to be set, you will need to issue a UID FETCH command.

@bagder
Copy link
Member

bagder commented Oct 18, 2021

thanks a lot for this feedback @mogery

It seems to suggest that it works as intended.

@jay
Copy link
Member

jay commented Oct 18, 2021

So it would seem this is a server issue, not a curl issue? Can we close this then?

@jay jay closed this as completed Oct 18, 2021
@jay jay reopened this Oct 18, 2021
@jay
Copy link
Member

jay commented Oct 18, 2021

Can we close this then?

Oops... meant to actually ask the question, not be snarky about it! Reopened.

@mogery
Copy link

mogery commented Oct 18, 2021

So it would seem this is a server issue, not a curl issue? Can we close this then?

It's user error. Seems closeable to me.

@jay jay added the not-a-bug This is not a bug in curl label Oct 18, 2021
@jay
Copy link
Member

jay commented Oct 18, 2021

It's user error. Seems closeable to me.

Ok thanks. Closing.

@jay jay closed this as completed Oct 18, 2021
@orycho
Copy link
Author

orycho commented Oct 18, 2021

I'm actually not happy about this as the same software I have in produciton behaves correctly with an old libcurl and incorrectly with a later one. So I would rule out a server issue.
My feeling is that there is a last bit of communication missing: the older version reported a last "flag /seen" before it was finished with the email fetch... but if nobody knows what causes that then we're stuck anyways.

@mogery
Copy link

mogery commented Oct 18, 2021

I'm actually not happy about this as the same software I have in produciton behaves correctly with an old libcurl and incorrectly with a later one. So I would rule out a server issue. My feeling is that there is a last bit of communication missing: the older version reported a last "flag /seen" before it was finished with the email fetch... but if nobody knows what causes that then we're stuck anyways.

That would be odd, because SEARCH commands do not implicitly set IMAP \Seen flags. That means, that with the code you linked, the current behaviour is the correct behaviour.

@orycho
Copy link
Author

orycho commented Oct 18, 2021

That example was specifically constructed as a minimal reproduciton example.
It fetches the email on lines 122 to 130. Fetch command is printed out on line 123 an performed on 130.
If you execute the code multiple times on a mail account with an unread mail, it should fetch and print the same email each time.
That was consistent with the versions I list in the original description.

@mogery
Copy link

mogery commented Oct 18, 2021

That example was specifically constructed as a minimal reproduciton example. It fetches the email on lines 122 to 130. Fetch command is printed out on line 123 an performed on 130. If you execute the code multiple times on a mail account with an unread mail, it should fetch and print the same email each time. That was consistent with the versions I list in the original description.

Oh, my apologies. I've misread the code. This is still pretty odd though.

What is the version of the old libcurl that the code was working on?

@orycho
Copy link
Author

orycho commented Oct 18, 2021

"I did this

I am using libcurl to fetch unseen emails from an account. Until curl version 7.55 (as far as I know) emails where then marked as read and where not foud again. This has changed by version 7.66 and probably still persists."

So, libcurl 7.55 is the version where it works.

@jay
Copy link
Member

jay commented Oct 18, 2021

I am using libcurl to fetch unseen emails from an account. Until curl version 7.55 (as far as I know) emails where then marked as read and where not foud again. This has changed by version 7.66 and probably still persists.

The confusion here might be that curl has switched its message retrieval mode from message sequence numbers to UID numbers.

For example

if you SEARCH UNSEEN and it returns 11970 that's a message sequence number.

but then you query via url ;UID=11970 but that's a UID number. if you turn on verbose mode in both you'll see any recent curl send UID FETCH 11970 BODY[], whereas older versions would send FETCH 11970 BODY[].

Try UID SEARCH UNSEEN to get the UID numbers, then pass that.

edit: Alternately since 7.62.0 you can use ;MAILINDEX=11970 to retrieve body via message sequence number however that is more error prone because message sequence numbers are relative and may be reassigned during a session.

@mogery
Copy link

mogery commented Oct 18, 2021

Try UID SEARCH UNSEEN to get the UID numbers, then pass that

+1

If you take a look at the output of the repro code, the mails that the code is printing out are ones that are actually already read.

@orycho
Copy link
Author

orycho commented Oct 18, 2021

Okay, that is something I an try. Thanks, I'll let you know tomorrow if that helped!

Cheers!

@orycho
Copy link
Author

orycho commented Oct 19, 2021

Hi, the UID SEARCH UNSEEN seems to do the trick. I thought I was doing UID only code, maybe the documentation could be reviewed? But that aside it's all good now.

Thanks for the help!

jay added a commit to jay/curl that referenced this issue Oct 19, 2021
- Explain the difference between IMAP search via URL (which returns
  message sequence numbers) and IMAP search via custom request (which
  can return UID numbers if prefixed with UID, eg "UID SEARCH ...").

Bug: curl#7626
Reported-by: orycho@users.noreply.github.com

Ref: curl#2789

Closes #xxxx
jay added a commit that referenced this issue Oct 21, 2021
- Explain the difference between IMAP search via URL (which returns
  message sequence numbers) and IMAP search via custom request (which
  can return UID numbers if prefixed with UID, eg "UID SEARCH ...").

Bug: #7626
Reported-by: orycho@users.noreply.github.com

Ref: #2789

Closes #7881
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IMAP not-a-bug This is not a bug in curl
Development

No branches or pull requests

4 participants