开发者

Parsing Email header fields using C/C++

开发者 https://www.devze.com 2023-02-10 08:51 出处:网络
I\'ve a C code where I fetch headers for all mails in the inbox via imap issuing UID FETCH 1:* (FLAGS BODY[HEADER]) command. Due to special authentication requirements I cannot use a standard imap lib

I've a C code where I fetch headers for all mails in the inbox via imap issuing UID FETCH 1:* (FLAGS BODY[HEADER]) command. Due to special authentication requirements I cannot use a standard imap library like vmime or libetpan. I need to parse the mail header values in accorda开发者_如何学运维nce with RFC 822. Do we have some library/function in C/C++ which will do the job ?


Mimetic works great ! it also takes care of non-standard mail headers.


Here is an example using mimetic:

void MailServer::PrintMimeStructure(MimeEntity* pMe)
{
    Header& h = pMe->header();  

    if(h.hasField("subject"))
        cout << "<subject>" << h.field("subject").value() << "</subject>" << 
        endl;

    if(h.hasField("from"))
        cout << "<from>" << h.field("from").value() << "</from>" << 
        endl;
    if(h.hasField("to"))
        cout << "<to>" << h.field("to").value() << "</to>" << 
        endl;
    if(h.hasField("message-id"))
        cout << "<message-id>" << h.field("message-id").value() << "</message-id>" << 
        endl;

    if(h.hasField("date"))
        cout << "<date>" << h.field("date").value() << "</date>" << 
        endl;       
}

This is what you need? Hope it helps!


A long time ago in a galaxy far, far away, I used the MIME++ library, now supported by Hunny Software: http://www.hunnysoft.com/mimepp/

It worked great at the time.

0

精彩评论

暂无评论...
验证码 换一张
取 消