function mailhandler_node_process_message in Mailhandler 7
Same name and namespace in other branches
- 6 mailhandler.module \mailhandler_node_process_message()
1 call to mailhandler_node_process_message()
- mailhandler_node_process_mailbox in ./
mailhandler.module - Run message retrieval and node processing on a mailbox - is a wrapper around mailhandler_retrieve
File
- ./
mailhandler.module, line 278
Code
function mailhandler_node_process_message($header, $origbody, $mailbox, $mimeparts) {
mailhandler_switch_user();
// we must process before authenticating because the password may be in Commands
$node = mailhandler_node_prepare_message($header, $origbody, $mailbox);
// Authenticate the message
if (!($node = mailhandler_mailhandler_authenticate('execute', $mailbox['authentication'], array(
$node,
$header,
$origbody,
$mailbox,
)))) {
watchdog('mailhandler', 'Message failed authentication', array(), WATCHDOG_ERROR);
return FALSE;
}
// Put $mimeparts on the node
$node->mimeparts = $mimeparts;
// we need to change the current user
// this has to be done here to allow modules
// to create users
mailhandler_switch_user($node->uid);
// modules may override node elements before submitting. they do so by returning the node.
foreach (module_list() as $name) {
if (module_hook($name, 'mailhandler')) {
$function = $name . '_mailhandler';
if (!($node = $function($node, $result, $i, $header, $mailbox))) {
// Exit if a module has handled the submitted data.
break;
}
}
}
if ($node) {
if ($node->type == 'comment') {
$nid = mailhandler_comment_submit($node, $header, $mailbox, $origbody);
$type = 'comment';
}
else {
$nid = mailhandler_node_submit($node, $header, $mailbox, $origbody);
$type = 'node';
}
}
// Invoke a second hook for modules to operate on the newly created/edited node/comment.
foreach (module_list() as $name) {
if (module_hook($name, 'mailhandler_post_save')) {
$function = $name . '_mailhandler_post_save';
// Pass in the $nid (which could be a $cid, depending on $node->type)
$function($nid, $type);
}
}
// switch back to original user
mailhandler_switch_user();
// Put something in the results array for the counter in the batch finished callback
$context['results'][] = $mailbox['mail'];
mailhandler_switch_user();
}