| 1 |
<?php |
<?php |
| 2 |
// $Id: mailhandler.module,v 1.87.2.15 2008/08/09 11:56:00 weitzman Exp $ |
// $Id: mailhandler.module,v 1.87.2.16 2008/09/14 15:26:07 zstolar Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Retrieve all msgs from a given mailbox and process them. |
* Retrieve all msgs from a given mailbox and process them. |
| 351 |
*/ |
*/ |
| 352 |
function mailhandler_term_map(&$term) { |
function mailhandler_term_map(&$term) { |
| 353 |
// provide case insensitive and trimmed map so as to maximize likelihood of successful mapping |
// provide case insensitive and trimmed map so as to maximize likelihood of successful mapping |
| 354 |
$term = db_result(db_query("SELECT tid FROM {term_data} WHERE LOWER('". trim($term) ."') LIKE LOWER(name)")); |
$term = db_result(db_query("SELECT tid FROM {term_data} WHERE LOWER('%s') LIKE LOWER(name)", trim($term))); |
| 355 |
} |
} |
| 356 |
|
|
| 357 |
/** |
/** |
| 366 |
$node->name = $from_user->name; |
$node->name = $from_user->name; |
| 367 |
} |
} |
| 368 |
else if (function_exists('mailalias_user')) { // since $fromaddress failed, try e-mail aliases |
else if (function_exists('mailalias_user')) { // since $fromaddress failed, try e-mail aliases |
| 369 |
$result = db_query("SELECT mail FROM {users} WHERE data LIKE '%%". $fromaddress ."%%'"); |
$result = db_query("SELECT mail FROM {users} WHERE data LIKE '%%%s%%'", $fromaddress); |
| 370 |
while ($alias = db_result($result)) { |
while ($alias = db_result($result)) { |
| 371 |
if ($from_user = mailhandler_user_load($alias, $node->pass, $mailbox)) { |
if ($from_user = mailhandler_user_load($alias, $node->pass, $mailbox)) { |
| 372 |
$node->uid = $from_user->uid; // success! |
$node->uid = $from_user->uid; // success! |
| 577 |
|
|
| 578 |
// Retrieve part convert MIME encoding to UTF-8 |
// Retrieve part convert MIME encoding to UTF-8 |
| 579 |
if(!$part->data = imap_fetchbody($stream, $msg_number, $part_number)) { |
if(!$part->data = imap_fetchbody($stream, $msg_number, $part_number)) { |
|
drupal_set_message("imap_fetchbody($stream, $msg_number, $part_number)"); |
|
| 580 |
watchdog('mailhandler', 'No Data!!', WATCHDOG_ERROR); |
watchdog('mailhandler', 'No Data!!', WATCHDOG_ERROR); |
| 581 |
return $parts; |
return $parts; |
| 582 |
} |
} |
| 613 |
} |
} |
| 614 |
|
|
| 615 |
/** |
/** |
|
* Implementation of hook_user(). |
|
|
* |
|
|
* Commented out because mailhandler cannot assume that this mailbox will |
|
|
* accept blog entries from users. |
|
|
*/ |
|
|
/* |
|
|
function mailhandler_user($type, &$edit, &$account, $category = NULL) { |
|
|
if ($type == 'view') { |
|
|
// @TODO: We may add a new option in mailboxes to choose which roles can post. |
|
|
if ((user_access('edit own blog') && $GLOBALS['user']->uid == $account->uid) || user_access('administer users')) { |
|
|
// for now, just show the first mailbox address to user. |
|
|
$mailbox = db_fetch_array(db_query('SELECT * FROM {mailhandler} WHERE enabled = 1 ORDER BY mail')); |
|
|
if ($mailbox) { |
|
|
if ($mailbox['security'] == 1) { |
|
|
$form = array( |
|
|
'#title' => t('Mail Handler'), |
|
|
'#value' => t('You may post to <a href="@blog">your blog</a> by sending an e-mail to %mail. Be sure to include your password at the top of your e-mail body (e.g. <em>pass=mypassword</em>).', array('@blog' => url("blog/$account->uid"), '%mail' => $mailbox['mail'])) |
|
|
); |
|
|
} |
|
|
else { |
|
|
$form = array( |
|
|
'#title' => t('Mail Handler'), |
|
|
'#value' => t('You may post to <a href="@blog">your blog</a> by sending an e-mail to %mail.', array('@blog' => url("blog/$account->uid"), '%mail' => $mailbox['mail'])) |
|
|
); |
|
|
} |
|
|
return array(t('Mail Handler') => array('mailhandler' => theme('item', $form))); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
*/ |
|
|
|
|
|
/** |
|
| 616 |
* Implementation of hook_cron(). Process msgs from all enabled mailboxes. |
* Implementation of hook_cron(). Process msgs from all enabled mailboxes. |
| 617 |
*/ |
*/ |
| 618 |
function mailhandler_cron() { |
function mailhandler_cron() { |
| 810 |
if ($edit['mid']) { |
if ($edit['mid']) { |
| 811 |
// Includes fields to allow administrators to add extra IMAP commands, |
// Includes fields to allow administrators to add extra IMAP commands, |
| 812 |
// and select the format of saved nodes/comments |
// and select the format of saved nodes/comments |
| 813 |
db_query("UPDATE {mailhandler} SET mail = '%s', mailto = '%s', domain = '%s', port = %d, folder = '%s', name = '%s', pass = '%s', extraimap = '%s', mime = '%s', imap = '%s', security = %d, replies = %d, fromheader = '%s', commands = '%s', sigseparator = '%s', enabled = %d, delete_after_read = %d, format = %d WHERE mid = '%s'", $edit['mail'], $edit['mailto'], $edit['domain'], $edit['port'], $edit['folder'], $edit['name'], $edit['pass'], $edit['extraimap'], $edit['mime'], $edit['imap'], $edit['security'], $edit['replies'], $edit['fromheader'], $edit['commands'], $edit['sigseparator'], $edit['enabled'], $edit['delete_after_read'], $edit['format'], $edit['mid']); |
db_query("UPDATE {mailhandler} SET mail = '%s', mailto = '%s', domain = '%s', port = %d, folder = '%s', name = '%s', pass = '%s', extraimap = '%s', mime = '%s', imap = '%s', security = %d, replies = %d, fromheader = '%s', commands = '%s', sigseparator = '%s', enabled = %d, delete_after_read = %d, format = %d WHERE mid = %d", $edit['mail'], $edit['mailto'], $edit['domain'], $edit['port'], $edit['folder'], $edit['name'], $edit['pass'], $edit['extraimap'], $edit['mime'], $edit['imap'], $edit['security'], $edit['replies'], $edit['fromheader'], $edit['commands'], $edit['sigseparator'], $edit['enabled'], $edit['delete_after_read'], $edit['format'], $edit['mid']); |
| 814 |
drupal_set_message(t('Mailbox updated')); |
drupal_set_message(t('Mailbox updated')); |
| 815 |
} |
} |
| 816 |
else { |
else { |