The PHP IMAP library uses the 'imap_headerinfo' function to grab the header objects. This function only returns a standard list of objects.

This patch tweaks the 'retrieve_message' function to include all of the header objects from an email.

With this tweak, the Mailhandler Extended Headers plugin can be used to grab any of these header objects. One example would be grabbing the 'List-Id' object from an email sent from a GNU Mailman email list.

This patch is based off the latest 7.x-2.x branch.

Comments

Status: Needs review » Needs work

The last submitted patch, mailhandler-php_imap_tweak.patch, failed testing.

danepowell’s picture

Awesome, thanks! I'll review this when I get a chance.

deltab’s picture

Status: Needs work » Needs review

mailhandler-php_imap_tweak.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, mailhandler-php_imap_tweak.patch, failed testing.

danepowell’s picture

Title: PHP IMAP tweak to get all header objects » Missing IMAP headers
Status: Needs work » Fixed

Fixed in 7.x-2.x-dev:
http://drupalcode.org/project/mailhandler.git/commit/ee2dad0

In the future, when submitting patches, please make sure that they conform to the Drupal code style guidelines. Thanks!

danepowell’s picture

Status: Fixed » Needs work

I reverted the previous commit, as it causes tests to fail.

ronin17’s picture

In the future, when submitting patches, please make sure that they conform to the Drupal code style guidelines. Thanks!

Whoops, sorry about that. For future reference, what part wasn't right?

I reverted the previous commit, as it causes tests to fail.

I meant to post this a while ago, but I did have to modify the 'MailhandlerCommandsHeaders.class.php' file:

Line 24 was originally:
$message[$key] = iconv_mime_decode($value, 0, "UTF-8");

I had to modify the decode options to continue on error, which looks like this:
$message[$key] = iconv_mime_decode($value, 2, "UTF-8");

I was trying to get some things done and didn't have a chance to take a look at what I could have done to prevent the error in the first place without modifying the iconv_mime_decode options. Do you have any suggestions?

Thanks.

danepowell’s picture

Use spaces instead of tabs, put opening brackets on the same line as conditionals, various other items... see https://drupal.org/coding-standards

I haven't had time to investigate why iconv_mime_decode is failing, but I agree that simply telling it to ignore failures is probably not the correct approach. Looking in depth at the structure of the returned headers would probably shed some light on the situation.

kscheirer’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new1.77 KB

Patch rerolled against 7.x-2.x-dev and updated to Drupal code standards.

Not sure what's causing iconv to fail either, a malformed (?) header that we're now grabbing?

danepowell’s picture

danepowell’s picture

Status: Fixed » Needs work

Well that's annoying... the patch passed tests, but when I actually committed it, the tests failed.

jurgenhaas’s picture

Status: Needs work » Needs review
StatusFileSize
new1.33 KB

Just came across the requirement to use this patch and then realized that this approach comes with a whitespace problem. Simply adding a trim() as first thing in the foreach loop is resolving the issue. Re-rolled patch is attached.

Status: Needs review » Needs work

The last submitted patch, 12: missing_imap_headers-1703018-12.patch, failed testing.

jurgenhaas’s picture

Status: Needs work » Needs review
StatusFileSize
new1.49 KB

Fix the patch

Status: Needs review » Needs work

The last submitted patch, 14: missing_imap_headers-1703018-14.patch, failed testing.

jurgenhaas’s picture

Now the patch properly applies but the tests fail. Reviewing them I doubt that the failures are related to the patch here, the system doesn't seem to be able to create the mappings for the test and as a consequence the received email doesn't contain the expected content.