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

use imap_fetchheader and imap_rfc822_parser_headers as fallback to receive from-header #138

Closed
wants to merge 1 commit into from
Closed

Conversation

mrohnstock
Copy link

@mrohnstock mrohnstock commented Oct 18, 2016

sometimes imap_header can't fetch the from-header (i.e. if utf-8 characters are included).

For example:

raw header from imap_fetchheader:

Return-Path: <[email protected]>
Received: from cluster.server.com ([xxx.xxx.xxx.xxx]) by mail.server.com
 (mouse [xxx.xxx.xxx.xxx]) with ESMTP (Nemesis) id 0MeRa7-1cLBGo0sQx-00QBRx
 for <[email protected]>; Fri, 14 Oct 2016 12:25:13 +0200
From: \"Universit\u00e4t Hamburg Marketing GmbH \" <[email protected]>
Reply-To: [email protected]
To: [email protected]
Subject: =?UTF-8?B?U3RlbGxlbndlcmstUmVjaG51bmcgMTYxMDExNDkgdm9tIDEzLjEwLjIw?=
\t=?UTF-8?B?MTY=?=
Date: Fri, 14 Oct 2016 10:25:13 GMT
MIME-Version: 1.0
Content-Type: multipart\/mixed;
\tboundary=\"-XimantiXSemanticMail\"
Envelope-To: <[email protected]>
X-UI-Filterresults: notjunk:1;V01:K0:1xdSVlc\/UH8=:MNtO5wvX\/NvFYa5\/e7Hvl3YCqp
 7AMD4ip7bykcH5vo400n+cv1q3ifL1UbzTHiF3hdyHJRWOfJD+5erji8LTJDz5DJ4DAVc99vh
 xpneIPRB8PofnNJ336iwwuGDMohzze5Z3LuIz11UUUZP8\/Gr8WwR1nXLBizAOuooxp0n7WiOY
 b4Jvt40nOiCe5nSISg6CsEVGHYA8Og7pjIeCejfbd43NKFf79QfGOVZi+zNrz94wCqIph1qUj
 GoOFWWC9VM+uCBim7mQ8wGCCMgP2X9qmy7ZbLgY1rOK7wQ9bXbHR0CiMuNHdpJag24e4Zd1rA
 aWtfOhjr07YOb23en0x1BBlh9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

parsed header by imap_header:

{  
   "date":"Fri, 14 Oct 2016 10:24:57 GMT",
   "Date":"Fri, 14 Oct 2016 10:24:57 GMT",
   "subject":"=?UTF-8?B?U3RlbGxlbndlcmstUmVjaG51bmcgMTYxMDExNDUgdm9tIDEzLjEwLjIw?=\t=?UTF-8?B?MTY=?=",
   "Subject":"=?UTF-8?B?U3RlbGxlbndlcmstUmVjaG51bmcgMTYxMDExNDUgdm9tIDEzLjEwLjIw?=\t=?UTF-8?B?MTY=?=",
   "toaddress":"[email protected]",
   "to":[  
      {  
         "mailbox":"test",
         "host":"example.com"
      }
   ],
   "reply_toaddress":"[email protected]",
   "reply_to":[  
      {  
         "mailbox":"info",
         "host":"mailserver.com"
      }
   ],
   "Recent":" ",
   "Unseen":" ",
   "Flagged":" ",
   "Answered":" ",
   "Deleted":" ",
   "Draft":" ",
   "Msgno":"   2",
   "MailDate":"14-Oct-2016 10:24:58 +0000",
   "Size":"94110",
   "udate":1476440698
}

I've added a fallback with the combination of imap_fetchheader and imap_rfc822_parse_headers, which will properly set the from-header:

{  
   "date":"Fri, 14 Oct 2016 10:24:57 GMT",
   "Date":"Fri, 14 Oct 2016 10:24:57 GMT",
   "subject":"=?UTF-8?B?U3RlbGxlbndlcmstUmVjaG51bmcgMTYxMDExNDUgdm9tIDEzLjEwLjIw?=\t=?UTF-8?B?MTY=?=",
   "Subject":"=?UTF-8?B?U3RlbGxlbndlcmstUmVjaG51bmcgMTYxMDExNDUgdm9tIDEzLjEwLjIw?=\t=?UTF-8?B?MTY=?=",
   "toaddress":"[email protected]",
   "to":[  
      {  
         "mailbox":"test",
         "host":"example.com"
      }
   ],
   "reply_toaddress":"[email protected]",
   "reply_to":[  
      {  
         "mailbox":"info",
         "host":"mailserver.com"
      }
   ],
   "Recent":" ",
   "Unseen":" ",
   "Flagged":" ",
   "Answered":" ",
   "Deleted":" ",
   "Draft":" ",
   "Msgno":"   2",
   "MailDate":"14-Oct-2016 10:24:58 +0000",
   "Size":"94110",
   "udate":1476440698,
   "from":[  
      {  
         "personal":"Universit\u00e4t Hamburg Marketing GmbH ",
         "mailbox":"message",
         "host":"mailserver.com"
      }
   ],
}

Slamdunk added a commit that referenced this pull request Sep 28, 2017
Add imap_fetchheader() functionality
Closes #29 #138 #149
@Slamdunk Slamdunk added this to the 1.0 milestone Sep 28, 2017
@Slamdunk
Copy link
Collaborator

From: \"Universit\u00e4t Hamburg Marketing GmbH \" <[email protected]> is not a valid header: I can't get the result you got with imap_rfc822_parse_headers.
We can't get rid of message flags: for this reason imap_headerinfo() will remain the main function.
Nevertheless now you can use it on your own: we've implemented the Message::getRawHeaders() method and you can apply imap_rfc822_parse_headers by hand.

Thank you for your feedback

@Slamdunk Slamdunk closed this Sep 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants