IMAP FETCH Subject
Asked Answered
N

3

12

Using IMAP via telnet, I want to be able to extract the subject from the specific given email. Now I know that the fetch command is responsible for getting data from an email.

My question is, how do I get the subject header specifically, without using a call to BODY[HEADER.FIELDS (SUBJECT)] (which will, in the eyes of the server, 'open the email' and thus set the /seen flag, which is what I don't want to occur)?

I understand FETCH FULL returns the full header, which contains the subject but it's a nightmare to parse through and could be riddled with unseen pitfalls if I manually parse it. How would I get the server to give me just the subject from the header?

Notorious answered 19/9, 2012 at 7:59 Comment(1)
I'm willing to consider alternatives so long as the /seen flag isn't set on usage.Notorious
N
21

I discovered the answer:

BODY.PEEK[HEADER.FIELDS (SUBJECT)]

.PEEK tells it not open it (so /seen isn't set).

Notorious answered 19/9, 2012 at 12:13 Comment(0)
L
4

Besides BODY.PEEK, you could fetch ENVELOPE, which gives you a parsed summary of much of the message metadata.

Lactary answered 19/9, 2012 at 13:7 Comment(0)
D
4

"a1 FETCH 1:* (FLAGS BODY[HEADER.FIELDS (SUBJECT DATE FROM)])\r\n"

Delocalize answered 6/6, 2014 at 0:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.