Send to multiple addresses
| Project: | Send |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | dww |
| Status: | reviewed & tested by the community |
As discussed at DrupalCon, here is the patch to allow people to send content to multiple addresses using send module.
The maximum number of recipient addresses is admin configurable. Addresses can be pasted in to a textarea from any handy e-mail or address book with the recipient name in front (typically in the "First Last format). I designed this to be quite flexible and (hopefully) intelligent, such that it should work with a wide variety of delimiters, or even a mixture or none at all (i.e. even "first1 last2 e1@example.com first2 last2 e2@example.com;<e3@example.com>" is correctly parsed). Both "First Last" and "Last, First" type name orders are parsed and neatly trimmed.
I added 'recipients' form value storage, so that _send_form_prepare() now just passes in a neat array of addresses, first and last names for any of the 3 form field cases. Each address is validated and, if they all pass, the submit handler mails each address.
- Owen
| Attachment | Size |
|---|---|
| multi_0_0.patch | 10.14 KB |

#1
Bump!
#2
Great start, Grugnog2, thanks! Shockingly, the original patch still applies. ;)
That said, here's a pretty major re-write to address some of the problems I found in the patch, both UI and implementation:
- The previous parsing to split recipients on email address was too fragile, and easily fooled. This version always splits on commas or newlines, and is more successful at finding and reporting invalid addresses. After an extensive IRC conversation with Grugnog, we decided it should actually require newlines to delimit addresses, and then still support
Last, First <email@example.com>style addresses, but that'll come as another patch.- Changed the UI for the setting to control max # of recipients, added validation, etc. It's only a small integer, so I don't see why we need 30 chars of a text field. ;)
- Fixed the code so that the setting just controls the max #, and it defaults to 1. Fixed disagreements over what the setting was called, which caused things not to work right in all cases in the previous patch.
- Form validate() callbacks don't need to return a value to specify success or failure, so I ripped that out.
- Sadly, if you call form_set_error() multiple times on the same form element, only the first message is printed. This is annoying for the recipients text area, since you can have multiple validation problems. So, we collect all our error messages in an array, use the first message for the form_set_error(), and display all the others via drupal_set_message().
- Fixed some code-style bugs.
- Fixed some improper uses of t(). For example, you shouldn't do stuff like
t('Foo') . check_plain($bar)because that becomes impossible to translate properly in RTL languages. You should really do:t('Foo @bar', array('@bar' => $bar))so that in RTL, folks can move the @bar placeholder whenever they need for it to make sense. Similarly, since %foo gets passed through theme('placeholder'), which itself does a check_plain(), the description for the multiple recipients from can just be:t('You can enter multiple e-mail addresses separated by commas or one per line. Use the format %example_email to specify names for each recipient.', array('%example_email' => t('First Last <email@example.com>')))- Removed some dead code about multiple recipients by way of separate form elements:
// recipients expanded into separate form fields// e.g. recipient1_first_name, recipient2_mail, and so-on
...
That stuff isn't actually present anywhere in the module, so I ripped it out since I think it'll be confusing with this new code...
I'll work on a new version that requires newlines to delimit addresses and supports commas for Last, First stuff... Meanwhile, anyone care to gives this a review and/or some testing, to see if there are any other problems? ;)
Thanks!
-Derek
#3
New patch:
- Requires each address to be on a separate line.
- Fixes up the UI for the send form itself. I couldn't get the long description for the multiple-recipients field to wrap nicely with the table width stuff. :( So, I took the somewhat evil hack approach of manually inserting a
<br />into the description to split it into 2 lines that fit. If there's a cleaner approach, I'm all ears, but this is the best I could do for now. I've attached screenshots of "wrap" and "no-wrap" so you can see what I mean.- Fixes a validation bug in the single-recipient case. ;) Glad I tested turning the setting back to max recipients == 1...
- Restores support for
Last, First <foo@example.com>that gets mapped toFirst Last <foo@example.com>This final point makes me wonder why we're in the business of parsing the name stuff at all. We just turn around and stick it all back together again in the end. Why use separate form fields, process it separately, etc, etc? Why not just grab the part of each line that looks like an email address as 'mail', and put the rest in 'name', and be done with it? Maybe that's a question for a follow-up patch...
Otherwise, I think this is now RTBC.
#4
Awesome. The patch applies cleanly to 5.x-1.0 and sending to multiple recipients works fine. I reviewed the patch briefly and it looks good.
#5
Hello there,
Any chance to implement the Drupal Contact List Importer ( or another one) so we could send a node / event to all the member sof our gmail or yahoo address book? This feature seems to be getting popular on social networking sites and it would be great to have it on drupal as well.
Anyhow, thank you all for the great input :):)
Expat9
#6
I did a brief check and couldn't tell, but this patch should take into account the flood control on a per-mail basis so we avoid something like http://drupal.org/node/398564