UDPATE: http://drupal.org/project/mail2og
I'm working on a connector between Mailhandler and organic groups that will allow site users to post content to groups via a specific email address. While mailhandler does support this the configuration that I'm interested in doesn't seem to exist yet. Instead of using Mailhandler's syntax for creating nodes, I want users to be able to post via a specific email address- for example groupname@mysite.com.
Mail2Web starts getting close to what I want- an ability to handle incoming emails and route them to specific nodes. Mailhandler offers a hook that allows other modules manipulate the node that is created- Mail2Web uses information in the email to figure out where to place the email. Thankfully, Mailhandler passes the headers of the original email through the hook, so it is possible to look at the to address of the email making it possible to route an email to a specific group. The problem, however is dealing with group names that are not quite obvious for email addresses.
For example, if the group name is "Our Great Group" an email address for this group needs some rules to map an approximation of this group name that is functional for email to the group name- the email address "Our Great Group@mysite.com" is obviously not a valid address. Because of this, users need to make some replacement of the spaces in the name and we need handle the character case in a non-strict way. To do this, it seems reasonable to do something like:
// breakup the to address so we can figure out to address
$pattern = '/^([^"].*?)@/';
preg_match($pattern, $header->toaddress, $matches);
// now clean the title with % so that we maybe are
// more likely of find it in the node table
$group_name = str_replace(array('_', '-', ' '), '%', $matches[1]);
// try to find the group with this title
$gid = db_result(db_query('SELECT n.nid FROM {node} n WHERE n.title LIKE "%s"', $group_name));
This gives us some flexibility for looking for the group name. However, I'm not quite convinced that this is the most elegant way to handle this- users are still responsible for figuring out what this address would be. A programmatic email name for groups that is displayed to group members is another option that could clarify where users should send emails- I'm not quite clear where that address would be displayed in the OG administration, but it is probably the best way to clarify things for end users.
The attached file is a rough go at making this connection.
| Attachment | Size |
|---|---|
| mail2og.tgz | 1.81 KB |

Post new comment