Bear with me on this, don't have much experience with recommending fixes or patches...
I set up a Feed importer to add emails to a site in hopes of associating that email with a contact by using their email address as a reference. In my 'email' content type I set up an email field that allows unlimited values. Using Rules I was going to create a entity reference on create.
Problem is that using the standard field mappings with Mailhandler, only one email address was being added to each node. I tried using Feeds Tamper->Explode using a comma as the delimiter on the full 'To address line' source. But, if the email address had a comma in name portion ("smith, j" ) then the Tamper would obviously split the source up at the wrong points.
So... going through the code I saw this on lines 8-25 of mailhandler/plugins/mailhandler/commands/MailhandlerCommandsHeaders.class.php
// Some headers are arrays of objects
if (in_array($key, array('to', 'from', 'reply_to', 'sender', 'cc', 'bcc', 'return_path'))) {
$message[$key . '-name'] = isset($value[0]->personal) ? iconv_mime_decode($value[0]->personal, 0, "UTF-8") : '';
$message[$key . '-address'] = (isset($value[0]->mailbox) && isset($value[0]->host)) ? $value[0]->mailbox . '@' . $value[0]->host : '';
}
else {
$message[$key] = iconv_mime_decode($value, 0, "UTF-8");
}
It looks like the code is only taking the first element of object and setting the item to that value. So I tried this:
// Some headers are arrays of objects
if (in_array($key, array('to', 'from', 'reply_to', 'sender', 'cc', 'bcc', 'return_path'))) {
$message[$key . '-name'] = array();
$message[$key . '-address'] = array();
foreach($value as $valkey => $val){
$message[$key . '-name'][$valkey] = isset($val->personal) ? iconv_mime_decode($val->personal, 0, "UTF-8") : '';
$message[$key . '-address'][$valkey] = (isset($val->mailbox) && isset($val->host)) ? $val->mailbox . '@' . $val->host : '';
}
}
else {
$message[$key] = iconv_mime_decode($value, 0, "UTF-8");
}
And viola, each individual address gets added as a separate value in my email field. I'm sure it's probably not a complete solution, but perhaps will help somebody along the way.
Thanks.
Comment | File | Size | Author |
---|---|---|---|
#5 | 1815688.4-mailhandler-better-addressee-support.patch | 2.28 KB | mrfelton |
#3 | 1815688-mailhandler-better-addressee-support.patch | 2.28 KB | mrfelton |
Comments
Comment #1
ordermind CreditAttribution: ordermind commentedThanks, this is how it should work!
Comment #2
Todd Young CreditAttribution: Todd Young commentedThis is superb and I was suffering from the same glitch... Can we get this rolled into a dev release?
Comment #3
mrfelton CreditAttribution: mrfelton commentedAttached is a patch to this effect. It also enhances the processing a little to provided dedicated mailbox and host properties.
Comment #5
mrfelton CreditAttribution: mrfelton commentedFix for syntax error i last patch.
Comment #6
Dane Powell CreditAttribution: Dane Powell commentedThanks for the patch, I applied it locally and will push to d.o once the repos are back online.
Does anyone know if Feeds 6.x parses in the same way? i.e. can this patch just be cherry-picked for 6.x? I guess we should write a simpletest for multiple email address mapping.
EDIT: commit:
http://drupalcode.org/project/mailhandler.git/commit/14716ec
Comment #7
nickonom CreditAttribution: nickonom commentedIs this functionality present in 7.x branch? Should I try to make it work with custom multiple e-mail field or by using Multiple E-mail Addresses module? Someone mentioned on that module about Mailhandler integration long time ago and I don't know if there were any actual attempts: https://www.drupal.org/node/201808#comment-10754276
Comment #8
nickonom CreditAttribution: nickonom commentedMy bad, guys, as I've just noticed there is in fact the Mailhandler Multiple Email support module. Would be nice to mention on the module's main page it works with Multiple Email module. Going to give it a try right away.