3 define(
'MAILINGLIST_ARCHIVE_VERSION', 1);
16 'administer mailinglist archive' => array(
17 'title' => t(
'Administer Mailinglist Archives'),
29 foreach ($lists as $index => $list) {
30 if (isset($list->operations[
'archive']) && $list->operations[
'archive']) {
42 'mailinglist_archive_thread' => array(
43 'worker callback' =>
'mailinglist_archive_thread_callback',
63 return 'plugins/' . $owner .
'/' . $plugin_type;
70 if($type !=
'module') {
74 'mailinglist_archive_form' => array(
75 'render element' =>
'element',
76 'file' =>
'mailinglist_archive_theme.inc',
78 'mailinglist_archive_form_header' => array(
79 'render element' =>
'element',
80 'file' =>
'mailinglist_archive_theme.inc',
82 'mailinglist_summary' => array(
83 'render element' =>
'element',
84 'file' =>
'mailinglist_archive_theme.inc',
86 'mailinglist_thread' => array(
87 'render element' =>
'element',
88 'file' =>
'mailinglist_archive_theme.inc',
90 'mailinglist_message' => array(
91 'render element' =>
'element',
92 'file' =>
'mailinglist_archive_theme.inc',
94 'mailinglist_body' => array(
95 'render element' =>
'element',
96 'file' =>
'mailinglist_archive_theme.inc',
106 'mailinglist_archive' => array(
107 'name' =>
'Mailing List Archive Message',
108 'base' =>
'mailinglist_message',
109 'description' =>
'Message archived for a mailing ist',
110 'help' =>
'(opt) Help displayed when creating nodes',
112 'title_lable' =>
'Subject',
128 return node_content_form($node, $form_state);
180 $list_name = $list->admin_name;
181 $list_schema = array();
182 $list_schema[
'mailinglist_archives__' . $list_name] = array(
183 'description' =>
'Table for holding the text of the messages',
189 'description' =>
'Primary Key for table',
194 'description' =>
'Message ID from message',
200 'description' =>
'mid of message we are a reply to',
202 'thread_id' => array(
206 'description' =>
'mid of first message of thread',
213 'description' =>
'Subject of Message',
240 'description' =>
'Index to Author\'s ID in mailinglist_names'
242 'author_email' => array(
249 'description' =>
'Time message was last updated (Debug)',
266 'description' =>
'published status, 0 = published, 1 = moderation queue, 2=waiting reply, 3=rejected',
272 'description' =>
'Version of the record (for development)',
278 'primary key' => array(
'mid'),
279 'unique keys' => array(
280 'msg_id' => array(array(
'msg_id', 100)),
283 'time' => array(
'time'),
284 'thread' => array(
'thread_id',
'time'),
285 'subject' => array(array(
'subject', 255),
'time'),
286 'author' => array(
'author',
'time'),
287 'author_email' => array(
'author_email'),
288 'hour' => array(
'hour'),
289 'reply_to' => array(
'reply_to',
'time'),
290 'time_parsed' => array(
'year',
'month',
'day'),
291 'updated' => array(
'updated',
'time',
'version'),
293 'foreign keys' => array(
295 'table' =>
'mailinglist_archives__' . $list_name,
296 'columns' => array(
'reply_to' =>
'mid'),
298 'thread_id' => array(
299 'table' =>
'mailinglist_archives__' . $list_name,
300 'columns' => array(
'thread_id' =>
'mid'),
303 'table' =>
'mailinglist_names',
304 'columns' => array(
'author' =>
'key'),
308 $list_schema[
'mailinglist_archives_references__' . $list_name] = array(
309 'description' =>
'Table to track the references of a message',
315 'description' =>
'mid of message these are references to',
321 'description' =>
'Sequence number for which ref this is for the meesage'
326 'description' =>
'mid of message we are a reply to',
328 'ref_msg_id' => array(
332 'description' =>
'Message ID of message we are a reply to',
335 'primary key' => array(
'mid',
'idx'),
337 'ref_mid' => array(
'ref_mid'),
338 'ref_msg_id' => array(array(
'ref_msg_id', 40)),
340 'foreign keys' => array(
342 'table' =>
'mailinglist_archives__' . $list_name,
343 'columns' => array(
'mid' =>
'mid'),
346 'table' =>
'mailinglist_archives__' . $list_name,
347 'columns' => array(
'ref_mid' =>
'mid'),
349 'ref_msg_id' => array(
350 'table' =>
'mailinglist_archives__' . $list_name,
351 'columns' => array(
'ref_msg_id' =>
'msg_id'),
355 $list_schema[
'mailinglist_archives_thread__' . $list_name] = array(
356 'description' =>
'Table for holding information about threads',
358 'thread_id' => array(
362 'description' =>
'mid of first message of thread',
365 'description' =>
'Time thread was started',
369 'description' =>
'Time thread was last posted to',
373 'primary key' => array(
'thread_id'),
375 'times' => array(
'start_time',
'last_time'),
377 'foreign keys' => array(
379 'table' =>
'mailinglist_archives__' . $list_name,
380 'columns' => array(
'thread_id' =>
'thread_id'),
386 $list->schema($list_schema,
'archive');
408 $listname = $list -> admin_name;
409 $table =
'mailinglist_archives__' . $listname;
410 $table_ref =
'mailinglist_archives_references__' . $listname;
411 $msg_id = $msg->header(
'Message-ID');
412 $from = $msg->headerEmail(
'From');
413 $subject = $msg->header(
'Subject');
414 $time = $msg->headerNoComments(
'Date');
415 $refs = $msg->header(
'References');
416 $refrply = $msg->headerNoComments(
'In-Reply-To');
417 $status = $msg->header(
'XX-Status');
419 if (!is_array($refs)) {
421 if (empty($refrply)) {
424 $refs = array($refrply);
427 $refs = explode(
' ', $refs);
433 $sql =
'SELECT * FROM {' . $table .
434 '} WHERE msg_id = :msgid';
435 $result = db_query($sql, array(
':msgid' => $msg_id)) -> fetchAssoc();
436 dpm($result,
'Old Version');
437 $incr = empty($result);
440 $headers = serialize($msg->headers());
441 $body = $msg->body();
442 $raw_body = $msg->raw();
444 $time = str_replace(array(
"US/Mountain"), array(
"America/Denver"), $time);
445 $ts = strtotime($time);
446 if($ts < strtotime(
'1980-01-01')) {
447 $list->log(
'Bad Date: ' . $time, $list::LOG_ERROR);
454 'year' => (
int)date(
'Y', $ts),
455 'month' => (
int)date(
'm', $ts),
456 'day' => (
int)date(
'd', $ts),
457 'hour' => (
int)date(
'h', $ts),
458 'subject' => substr($subject, 0, 255),
460 'author_email' => $from[
'email'],
462 'headers' => $headers,
463 'raw_body' => $raw_body,
464 'status' => (
int)$status,
469 if (empty($result)) {
470 dpm($info,
'New Record');
472 $mid = db_insert($table) ->fields($info) -> execute();
473 $info[
'thread_id'] = $mid;
476 $info[
'status'] = min($info[
'status'], (
int)$result[
'status']);
477 $mid = $result[
'mid'];
479 if(($info[
'thread_id'] == 0) or ($info[
'reply_to'] == 0)) {
480 $info[
'thread_id'] = $mid;
483 dpm($info,
'Update Record');
484 db_update($table) -> fields($info) -> condition(
'mid', $mid) -> execute();
489 foreach ($refs as $idx => $ref) {
491 $sql =
'SELECT mid FROM {' . $table .
'} WHERE msg_id = :msgid';
492 $result = db_query($sql, array(
':msgid' => $ref)) -> fetchAssoc();
494 $ref_mid = $result[
'mid'];
502 'ref_mid' => $ref_mid,
503 'ref_msg_id' => $ref,
505 dpm($info_ref,
'Reference');
506 $sql =
'SELECT * FROM {' . $table_ref .
'} WHERE mid = :mid AND idx = :idx';
507 $result = db_query($sql, array(
':mid' => $mid,
':idx' => $idx)) ->fetchAssoc();
509 db_update($table_ref) -> fields($info_ref) -> condition(
'mid', $mid) ->
510 condition(
'idx', $idx) -> execute();
512 db_insert($table_ref) -> fields($info_ref) -> execute();
518 }
catch (Exception $e) {
519 watchdog(
'mailinglist',
'Exception in mailinglist_archive_message_add: @e ',
520 array(
'@e' => print_r($e,
true)), WATCHDOG_ERROR);
534 $listname = $list -> admin_name;
535 $table =
'mailinglist_archives__' . $listname;
536 $table_ref =
'mailinglist_archives_references__' . $listname;
542 $sql =
'SELECT ref_mid
543 FROM {' . $table_ref .
'} as r, {' . $table .
'} as m
544 WHERE r.mid = :mid AND r.ref_mid = m.mid and m.status = 0
545 ORDER BY r.idx ASC LIMIT 1';
546 $result = db_query($sql, array(
':mid' => $mid)) -> fetchAssoc();
547 dpm($result,
'Link Info');
549 $reply_to = $result[
'ref_mid'];
550 $sql =
'SELECT * FROM {' . $table .
'} WHERE mid = :mid';
551 $result = db_query($sql, array(
':mid' => $reply_to)) -> fetchAssoc();
552 $thread_id = $result[
'thread_id'];
557 $info = array(
'reply_to' => $reply_to,
'thread_id' => $thread_id);
558 db_update($table) -> fields($info) -> condition(
'mid', $mid) -> execute();
561 $sql =
'SELECT MIN( `time` ) AS start_time, MAX( `time` ) AS last_time
562 FROM {mailinglist_archives__' . $listname .
'}
563 WHERE thread_id =:tid
565 $result = db_query($sql, array(
':tid' => $thread_id)) -> fetchAssoc();
566 dpm($result,
'Threading');
568 db_merge(
'mailinglist_archives_thread__' . $listname)
569 -> key(array(
'thread_id' => $thread_id))
581 $listname = $list -> admin_name;
582 $table_ref =
'mailinglist_archives_references__' . $listname;
585 $sql =
'SELECT * FROM {' . $table_ref .
'} WHERE ref_msg_id = :msgid';
586 $result = db_query($sql, array(
':msgid' => $msgid));
587 while($row = $result -> fetchAssoc()) {
589 if ($row[
'ref_mid'] != $mid) {
591 $ref_mid = $row[
'mid'];
592 $ref_idx = $row[
'idx'];
596 db_update($table_ref) -> fields($info_ref) -> condition(
'mid', $ref_mid) ->
597 condition(
'idx', $ref_idx) -> execute();
607 $listname = $list->admin_name;
608 $tablename =
'mailinglist_archives__' . $listname;
609 $base = variable_get(
'mailinglist_base',
'mailinglist');
611 if(!is_array($vars)) {
612 if(is_numeric($vars) && $cond ==
'') {
618 if(is_numeric($cond)){
619 $vars[
':mid'] = $cond;
620 $cond =
'a.mid = :mid';
624 $order =
'ORDER BY a.time ASC';
630 if(is_numeric($limit)) {
631 $limit =
"LIMIT $limit";
634 $sql =
'Select * FROM
635 {' . $tablename .
'} AS a
636 LEFT JOIN {mailinglist_names} AS n ON a.author = n.name_key';
638 $sql .=
' WHERE ' . $cond;
640 $sql .=
' ' . $order .
' ' . $limit;
643 '#theme' =>
'mailinglist_thread',
649 $result = db_query($sql, $vars);
651 while($row = $result -> fetchAssoc()) {
652 $data[
'items'][] = array(
653 '#theme' =>
'mailinglist_summary',
656 'subject' => array(
'#markup' => $row[
'subject']),
657 'email' => array(
'#markup' => $row[
'email']),
658 'name' => array(
'#markup' => $row[
'name']),
659 'url' => array(
'#item' =>
"$base/$listname/archive/msg/" . $row[
'mid']),
662 '#mid' => $row[
'mid'],
663 '#reply_to' => $row[
'reply_to'],
672 'a.reply_to = :mid',
'ORDER BY a.time ASC');
673 $replies[
'#level'] = $n;
675 foreach($replies[
'items'] as $key => &$item) {
687 $tablename =
'mailinglist_archives__' . $list->admin_name;
688 $sql =
'SELECT * FROM {' . $tablename.
'} AS a,
689 {mailinglist_names} as n
690 WHERE a.mid = :mid AND a.author = n.name_key';
691 $result = db_query($sql, array(
':mid' => $msgid)) -> fetchAssoc();
699 if ($msg->header(
'XX-Archive')) {
708 $queue = DrupalQueue::get(
'mailinglist_message');
709 if($queue->numberOfItems() > 0) {
714 $listname = $list->admin_name;
716 $sql =
'SELECT * FROM {mailinglist_archives__' . $listname .
'}
717 ORDER BY updated ASC, time ASC LIMIT 10';
718 $result = db_query($sql, array());
719 while($row = $result -> fetchAssoc()) {
720 dpm($row,
'Refresh Scan');
721 $msg = $row[
'raw_body'];
725 $from = $msg->header(
'From');
726 if (is_array($from)) {
730 if (strpos($from,
'@') == FALSE) {
732 $from = str_replace(
' at ',
'@', $from);
733 $msg->setHeader(
'From', $from);
737 $msg->setHeader(
'XX-List', $list->admin_name);
738 $msg->setHeader(
'XX-Archive',
'1');
739 $msg->setHeader(
'XX-Status', $row[
'status']);
740 $list->processMessage($msg);
mailinglist_archive_message_ref_id($list, $mid, $msgid)
mailinglist_archive_message_ref_id().
mailinglist_archive_theme($existing, $type, $theme, $path)
Implements hook_theme().
mailinglist_message_insert($node)
Implements hook_insert().
mailinglist_archive_message_add($msg, $list)
mailinglist_archive_message_add().
Class defining the contents of an e-mail message.
mailinglist_archive_permission()
Implements hook_permission().
mailinglist_archive_cron()
Implements hook_cron().
mailinglist_archive_cron_queue_info()
Implements hook_cron_queue_info().
mailinglist_message_delete($node)
Implements hook_delete().
mailinglist_message_load($nodes)
Implements hook_load().
_mailinglist_archives_list_schema($list)
_mailinnglist)archives_list_schema()
mailinglist_archive_message_link($list, $mid)
mailinglist_archive_message_link().
mailinglist_archive_ctools_plugin_directory($owner, $plugin_type)
Implements hook_ctools_plugin_directory().
mailinglist_message_form($node, &$form_state)
Implements hook_form().
_mailinglist_datetime_schema($desc)
Return the schema for a 'datetime' field.
_mailinglist_archive_scan($list)
Perform incremental scan of archive for problems.
mailinglist_email_name($email, $name, $count=0)
Lookup Email <-> Name combination.
mailinglist_archive_reply_tree($list, $msgid, $n=0)
mailinglist_archive_message_get($list, $msgid)
Get a full message by Msg ID.
mailinglist_archive_summary_list($list, $vars, $cond= '', $order="", $limit="")
Return list of message summaries.
mailinglist_archive_thread_callback($thread)
const MAILINGLIST_ARCHIVE_VERSION
mailinglist_message_update($node)
Implements hook_update().
mailinglist_list_load_all($show_disabled=TRUE)
Load all mailinglists.
mailinglist_archive_mailinglist_message($msg, $list)
Implements hook_mailinglist_message().
_mailinglist_datetime_format($ts)
Convert a 'timestamp to a 'datetime'.
mailinglist_archive_node_info()
Implments hook_node_info().
_mailinglist_datetime_ts($time)
Convert a 'datetime' field into a timestamp.