function mailhandler_authenticate in Mailhandler 5
Determine who is the author of the upcoming node.
1 call to mailhandler_authenticate()
- mailhandler_retrieve in ./
mailhandler.module - Retrieve all msgs from a given mailbox and process them.
File
- ./
mailhandler.module, line 358
Code
function mailhandler_authenticate($node, $header, $origbody, $mailbox) {
// $fromaddress really refers to the mail header which is authoritative for authentication
list($fromaddress, $fromname) = mailhandler_get_fromaddress($header, $mailbox);
if ($from_user = mailhandler_user_load($fromaddress, $node->pass, $mailbox)) {
$node->uid = $from_user->uid;
// success!
$node->name = $from_user->name;
}
else {
if (function_exists('mailalias_user')) {
// since $fromaddress failed, try e-mail aliases
$result = db_query("SELECT mail FROM {users} WHERE data LIKE '%%%s%%'", $fromaddress);
while ($alias = db_result($result)) {
if ($from_user = mailhandler_user_load($alias, $node->pass, $mailbox)) {
$node->uid = $from_user->uid;
// success!
$node->name = $from_user->name;
break;
}
}
}
}
if (!$from_user) {
// failed authentication. we will still try to submit anonymously.
$node->uid = 0;
$node->name = $fromname;
// use the name supplied in email headers
}
return $node;
}