Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IMAP FETCH Subject

Tags:

imap

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?

like image 714
user1433767 Avatar asked Sep 19 '12 07:09

user1433767


2 Answers

I discovered the answer:

BODY.PEEK[HEADER.FIELDS (SUBJECT)]

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

like image 133
user1433767 Avatar answered Jan 06 '23 03:01

user1433767


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

like image 41
Nicolás Schmidt Gubbins Avatar answered Jan 06 '23 05:01

Nicolás Schmidt Gubbins