| 1 |
<?php |
<?php |
| 2 |
// $Id: |
// $Id: initialize $ |
| 3 |
|
|
| 4 |
/* |
/* |
| 5 |
** mail_archive.module: |
** mail_archive.module: |
| 635 |
function mail_archive_cron() { |
function mail_archive_cron() { |
| 636 |
$last_check = variable_get('mail_archive_checked_mail', ''); |
$last_check = variable_get('mail_archive_checked_mail', ''); |
| 637 |
|
|
| 638 |
// download and index new messages |
// download and index new messages no more than once every five minutes |
| 639 |
if ((time() - $last_check) >= variable_get('mail_archive_download_time', 300)) { |
if ((time() - $last_check) >= variable_get('mail_archive_download_time', 300)) { |
| 640 |
$result = db_query('SELECT s.*, n.title FROM {mail_archive_subscriptions} s INNER JOIN {node} n ON s.nid = n.nid WHERE subscription_status = 1'); |
$result = db_query('SELECT s.*, n.title FROM {mail_archive_subscriptions} s INNER JOIN {node} n ON s.nid = n.nid WHERE subscription_status = 1'); |
| 641 |
while ($subscription = db_fetch_object($result)) { |
while ($subscription = db_fetch_object($result)) { |
| 642 |
mail_archive_fetch_mail($subscription); |
mail_archive_fetch_mail($subscription); |
| 643 |
|
/* give the mail system time to catch up (downloading a large number of |
| 644 |
|
** subscriptions at one time without pause can result in the last few |
| 645 |
|
** failing.) |
| 646 |
|
*/ |
| 647 |
|
sleep (1); |
| 648 |
} |
} |
| 649 |
variable_set('mail_archive_checked_mail', time()); |
variable_set('mail_archive_checked_mail', time()); |
| 650 |
} |
} |
| 655 |
} |
} |
| 656 |
|
|
| 657 |
function mail_archive_insert($node) { |
function mail_archive_insert($node) { |
| 658 |
|
watchdog('mail_archive', t('Mail archive subscription "%title" created.', array('%title' => $node->title))); |
| 659 |
db_query('INSERT INTO {mail_archive_subscriptions} (nid, created, server, port, folder, username, password, connection, delete_read, subscription_status) VALUES(%d, %d, "%s", %d, "%s", "%s", "%s", %d, %d, %d)', $node->nid, $node->created, $node->server, $node->port, $node->folder, $node->username, $node->password, $node->connection, $node->delete_read, $node->subscription_status); |
db_query('INSERT INTO {mail_archive_subscriptions} (nid, created, server, port, folder, username, password, connection, delete_read, subscription_status) VALUES(%d, %d, "%s", %d, "%s", "%s", "%s", %d, %d, %d)', $node->nid, $node->created, $node->server, $node->port, $node->folder, $node->username, $node->password, $node->connection, $node->delete_read, $node->subscription_status); |
| 660 |
} |
} |
| 661 |
|
|
| 664 |
} |
} |
| 665 |
|
|
| 666 |
function mail_archive_delete($node) { |
function mail_archive_delete($node) { |
| 667 |
|
watchdog('mail_archive', t('Mail archive subscription "%title" deleted.', array('%title' => $node->title))); |
| 668 |
// TODO: figure out what to do with mail archive (delete everything?) |
// TODO: figure out what to do with mail archive (delete everything?) |
| 669 |
db_query('DELETE FROM {mail_archive_subscriptions} WHERE nid = %d', $node->nid); |
db_query('DELETE FROM {mail_archive_subscriptions} WHERE nid = %d', $node->nid); |
| 670 |
// currently we leave everything related to a subscription orphaned |
// currently we leave everything related to a subscription orphaned |
| 1289 |
// update subscription message count |
// update subscription message count |
| 1290 |
db_query('UPDATE {mail_archive_subscriptions} SET messages = messages - 1 WHERE lid = %d', $lid); |
db_query('UPDATE {mail_archive_subscriptions} SET messages = messages - 1 WHERE lid = %d', $lid); |
| 1291 |
|
|
| 1292 |
|
watchdog('mail_archive', t('Message "%subject" delete from mail archive "%title".', array('%subject' => $message->subject_short, '%title' => mail_archive_get_subscription_name($lid)))); |
| 1293 |
|
|
| 1294 |
// go back to list overview |
// go back to list overview |
| 1295 |
drupal_goto("mailarchive/$lid/overview/thread"); |
drupal_goto("mailarchive/$lid/overview/thread"); |
| 1296 |
} |
} |
| 1438 |
} |
} |
| 1439 |
$mailbox = @imap_open($connect, $username, $password); |
$mailbox = @imap_open($connect, $username, $password); |
| 1440 |
if ($mailbox === FALSE) { |
if ($mailbox === FALSE) { |
| 1441 |
|
watchdog('mail_archive', t('Connection to mail server "%server" with username "%username"failed', array('%server' => $connect, '%username' => $username))); |
| 1442 |
drupal_set_message (t('Connection to mail server "%server" failed.<br />', array('%server' => $connect)), 'error'); |
drupal_set_message (t('Connection to mail server "%server" failed.<br />', array('%server' => $connect)), 'error'); |
| 1443 |
if ($alerts = imap_alerts()) { |
if ($alerts = imap_alerts()) { |
| 1444 |
foreach ($alerts as $alert) { |
foreach ($alerts as $alert) { |
| 1485 |
|
|
| 1486 |
if ($messages_downloaded) { |
if ($messages_downloaded) { |
| 1487 |
db_query('UPDATE {mail_archive_subscriptions} SET messages = messages + %d, last = %d WHERE lid = %d', $messages_downloaded, time(), $subscription->lid); |
db_query('UPDATE {mail_archive_subscriptions} SET messages = messages + %d, last = %d WHERE lid = %d', $messages_downloaded, time(), $subscription->lid); |
| 1488 |
drupal_set_message(t('Succesfully fetched %number messages.', array('%number' => $messages_downloaded))); |
drupal_set_message(t('Successfully fetched %number messages for "%subscription".', array('%number' => $messages_downloaded, '%subscription' => $subscription->title))); |
| 1489 |
} |
} |
| 1490 |
else { |
else { |
| 1491 |
drupal_set_message('No messages were downloaded.'); |
drupal_set_message('No messages were downloaded.'); |