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?

user1433767
  • 645
  • 2
  • 6
  • 14

3 Answers3

21

I discovered the answer:

BODY.PEEK[HEADER.FIELDS (SUBJECT)]

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

user1433767
  • 645
  • 2
  • 6
  • 14
4

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

Max
  • 10,701
  • 2
  • 24
  • 48
4

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