/[drupal]/contributions/modules/mail_archive/mail_archive.module
ViewVC logotype

Diff of /contributions/modules/mail_archive/mail_archive.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.15 by jeremy, Sat Feb 5 19:01:12 2005 UTC revision 1.16 by jeremy, Thu Feb 10 04:34:22 2005 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: initialize $  // $Id: mail_archive.module,v 1.15 2005/02/05 19:01:12 jeremy Exp $
3    
4  /*  /*
5  ** mail_archive.module:  ** mail_archive.module:
# Line 243  function theme_mail_archive_message_flat Line 243  function theme_mail_archive_message_flat
243    $output .= theme('mail_archive_message_replyto', $message->reply_to);    $output .= theme('mail_archive_message_replyto', $message->reply_to);
244    $output .= theme('mail_archive_message_raw_link', $message);    $output .= theme('mail_archive_message_raw_link', $message);
245    $output .= ' ';    $output .= ' ';
246      $output .= theme('mail_archive_message_edit_link', $message);
247      $output .= ' ';
248    $output .= theme('mail_archive_message_delete_link', $message);    $output .= theme('mail_archive_message_delete_link', $message);
249    $output .= theme('mail_archive_message_header', $message);    $output .= theme('mail_archive_message_header', $message);
250    $output .= theme('mail_archive_message_body', $message);    $output .= theme('mail_archive_message_body', $message);
# Line 256  function theme_mail_archive_message_thre Line 258  function theme_mail_archive_message_thre
258    $output .= '<div class="message-thread">';    $output .= '<div class="message-thread">';
259    $output .= theme('mail_archive_message_raw_link', $message);    $output .= theme('mail_archive_message_raw_link', $message);
260    $output .= ' ';    $output .= ' ';
261      $output .= theme('mail_archive_message_edit_link', $message);
262      $output .= ' ';
263    $output .= theme('mail_archive_message_delete_link', $message);    $output .= theme('mail_archive_message_delete_link', $message);
264    $output .= theme('mail_archive_message_header', $message);    $output .= theme('mail_archive_message_header', $message);
265    $output .= theme('mail_archive_message_body', $message);    $output .= theme('mail_archive_message_body', $message);
# Line 307  function theme_mail_archive_message_dele Line 311  function theme_mail_archive_message_dele
311    return $output;    return $output;
312  }  }
313    
314    function theme_mail_archive_message_edit_link($message) {
315      $output = '';
316      if (user_access('administer mail archive')) {
317        $output .= '<span class="message-edit-link">';
318        $output .=  l(t('edit message'), url("mailarchive/$message->lid/message/$message->mid/edit"));
319        $output .= '</span>';
320      }
321      return $output;
322    }
323    
324  function theme_mail_archive_display($categories, $subscriptions, $parents, $tid, $subscriptions_per_page) {  function theme_mail_archive_display($categories, $subscriptions, $parents, $tid, $subscriptions_per_page) {
325    global $user;    global $user;
326    
# Line 502  function mail_archive_menu($may_cache) { Line 516  function mail_archive_menu($may_cache) {
516                         'access' => user_access('access mail archive'),                         'access' => user_access('access mail archive'),
517                         'type' => MENU_LOCAL_TASK,                         'type' => MENU_LOCAL_TASK,
518                         'weight' => 2);                         'weight' => 2);
519    /* TODO: remove?
520        $items[] = array('path' => "mailarchive/$lid/message/$mid/rethread",        $items[] = array('path' => "mailarchive/$lid/message/$mid/rethread",
521                         'title' => t('rebuild thread'),                         'title' => t('rebuild thread'),
522                         'description' => t('force a rebuild of the current message thread'),                         'description' => t('force a rebuild of the current message thread'),
# Line 509  function mail_archive_menu($may_cache) { Line 524  function mail_archive_menu($may_cache) {
524                         'access' => user_access('administer mail archive'),                         'access' => user_access('administer mail archive'),
525                         'type' => MENU_LOCAL_TASK,                         'type' => MENU_LOCAL_TASK,
526                         'weight' => 8);                         'weight' => 8);
527    */
528        $items[] = array('path' => "mailarchive/$lid/message/$mid/raw",        $items[] = array('path' => "mailarchive/$lid/message/$mid/raw",
529                         'callback' => 'mail_archive_overview',                         'callback' => 'mail_archive_overview',
530                         'access' => user_access('access mail archive'),                         'access' => user_access('access mail archive'),
531                         'type' => MENU_SUGGESTED_ITEM);                         'type' => MENU_SUGGESTED_ITEM);
532          $items[] = array('path' => "mailarchive/$lid/message/$mid/edit",
533                           'callback' => 'mail_archive_overview',
534                           'access' => user_access('administer mail archive'),
535                           'type' => MENU_SUGGESTED_ITEM);
536        $items[] = array('path' => "mailarchive/$lid/message/$mid/delete",        $items[] = array('path' => "mailarchive/$lid/message/$mid/delete",
537                         'callback' => 'mail_archive_overview',                         'callback' => 'mail_archive_overview',
538                         'access' => user_access('administer mail archive'),                         'access' => user_access('administer mail archive'),
# Line 1023  function mail_archive_load_filter($lid) Line 1043  function mail_archive_load_filter($lid)
1043  }  }
1044    
1045  function mail_archive_load_message($lid, $mid) {  function mail_archive_load_message($lid, $mid) {
1046    $message = db_fetch_object(db_query('SELECT mid, lid, mailfrom, mailfrom_short, mailto, subject, subject_short, received, path, attachments, reference, message_id, thread_id, sub_thread_id, bodytype FROM {mail_archive_message_index} WHERE lid = %d AND mid = %d', $lid, $mid));    $message = db_fetch_object(db_query('SELECT mid, lid, mailfrom, mailfrom_short, mailto, subject, subject_short, received, path, attachments, reference, message_id, thread_id, sub_thread_id, bodytype, in_reply_to, in_reply_tos FROM {mail_archive_message_index} WHERE lid = %d AND mid = %d', $lid, $mid));
1047    if ($message->attachments) {    if ($message->attachments) {
1048      $message->attachments_result = db_query('SELECT * FROM {mail_archive_attachments_index} WHERE mid = %d', $mid);      $message->attachments_result = db_query('SELECT * FROM {mail_archive_attachments_index} WHERE mid = %d', $mid);
1049    }    }
# Line 1057  function mail_archive_message_thread_top Line 1077  function mail_archive_message_thread_top
1077    $sql = "SELECT mid, subject_short, mailfrom_short, received, thread_id FROM {mail_archive_message_index} WHERE lid = $lid AND thread_id = $message->thread_id ORDER BY sub_thread_id DESC";    $sql = "SELECT mid, subject_short, mailfrom_short, received, thread_id FROM {mail_archive_message_index} WHERE lid = $lid AND thread_id = $message->thread_id ORDER BY sub_thread_id DESC";
1078    $thread_top = db_fetch_object(pager_query($sql, 1));    $thread_top = db_fetch_object(pager_query($sql, 1));
1079    return ($thread_top);    return ($thread_top);
   
1080  }  }
1081    
1082  function mail_archive_message_thread_next($lid, $mid) {  function mail_archive_message_thread_next($lid, $mid) {
# Line 1087  function mail_archive_display_message($l Line 1106  function mail_archive_display_message($l
1106      case 'delete':      case 'delete':
1107        $output = mail_archive_message_delete($lid, $id);        $output = mail_archive_message_delete($lid, $id);
1108        break;        break;
1109        case 'edit':
1110          // TODO: allow update of entire message
1111          $edit = $_POST['edit'];
1112          if($edit['parent_id']) {
1113            $parent = db_fetch_object(db_query("SELECT message_id, thread_id FROM {mail_archive_message_index} WHERE lid = %d AND mid = '%s'", $lid, $edit['parent_id']));
1114            db_query("UPDATE {mail_archive_message_index} SET in_reply_to = '%s', in_reply_tos = 0 WHERE lid = %d and mid = %d", $parent->message_id, $lid, $id);
1115            mail_archive_rethread($lid, $parent->thread_id);
1116            drupal_set_message(t('Message updated.'));
1117            drupal_goto("mailarchive/$lid/message/$id/thread");
1118          }
1119          else {
1120            $message = mail_archive_load_message($lid, $id);
1121            if (!$message->in_reply_tos && $message->in_reply_to != '') {
1122              $parent = db_fetch_object(db_query("SELECT mid FROM {mail_archive_message_index} WHERE lid = %d AND message_id = '%s'", $lid, $message->in_reply_to));
1123            }
1124            $output = form_textfield(t('Parent message id'), 'parent_id', $parent->mid, 10, 255, t('The message id of message that is the parent of this message.  If this message should not have a parent, leave this field blank.'));
1125            $output .= form_submit(t('Update threading'));
1126            $output = form($output);
1127          }
1128          break;
1129      case 'thread':      case 'thread':
1130        $output = "<div class=\"message\">\n";        $output = "<div class=\"message\">\n";
1131    
1132        $messages_per_page = $_GET['messages_per_page'];        $messages_per_page = $_GET['messages_per_page'];
1133        if (!(int)$messages_per_page) {        if (!(int)$messages_per_page) {
1134          $messages_per_page = 10;          $messages_per_page = 10;
1135        }        }
1136    
1137        // load first message to get thread details        // load first message to get thread details
# Line 1124  function mail_archive_display_message($l Line 1163  function mail_archive_display_message($l
1163        // now load and display the full thread        // now load and display the full thread
1164        $sql = "SELECT mid FROM {mail_archive_message_index} WHERE lid = $lid AND thread_id = $thread_id AND (sub_thread_id LIKE '$sub_thread_id.%%' OR mid = $id) GROUP BY mid, thread_id, subject_short, received, sub_thread_id ORDER BY thread_id DESC, sub_thread_id DESC";        $sql = "SELECT mid FROM {mail_archive_message_index} WHERE lid = $lid AND thread_id = $thread_id AND (sub_thread_id LIKE '$sub_thread_id.%%' OR mid = $id) GROUP BY mid, thread_id, subject_short, received, sub_thread_id ORDER BY thread_id DESC, sub_thread_id DESC";
1165        $result = pager_query($sql, $messages_per_page, 0, "SELECT COUNT(thread_id) FROM {mail_archive_message_index} WHERE lid = $lid AND thread_id = $thread_id AND (sub_thread_id LIKE '$sub_thread_id.%%' OR mid = $id)");        $result = pager_query($sql, $messages_per_page, 0, "SELECT COUNT(thread_id) FROM {mail_archive_message_index} WHERE lid = $lid AND thread_id = $thread_id AND (sub_thread_id LIKE '$sub_thread_id.%%' OR mid = $id)");
1166    
1167        if ($pager = theme('pager', NULL, $messages_per_page, 0, array('messages_per_page' => $messages_per_page))) {        if ($pager = theme('pager', NULL, $messages_per_page, 0, array('messages_per_page' => $messages_per_page))) {
1168          $output .= $pager;          $output .= $pager;
1169          $output .= '<hr /><br />';          $output .= '<hr /><br />';
# Line 1167  function mail_archive_display_message($l Line 1206  function mail_archive_display_message($l
1206        $output .= "</div>\n";        $output .= "</div>\n";
1207        break;        break;
1208      case 'rethread':      case 'rethread':
1209        $message = db_fetch_object(db_query('SELECT thread_id FROM {mail_archive_message_index} WHERE lid = %d AND mid = %d', $lid, $id));        // auto-rethreading should be unnecessary, but leave code here in case
1210        mail_archive_rethread($lid, $message->thread_id);        //$message = db_fetch_object(db_query('SELECT thread_id FROM {mail_archive_message_index} WHERE lid = %d AND mid = %d', $lid, $id));
1211        drupal_goto("mailarchive/$lid/message/$id/thread");        //mail_archive_rethread($lid, $message->thread_id);
1212          //drupal_goto("mailarchive/$lid/message/$id/thread");
1213        break;        break;
1214      default: // flat      default: // flat
1215        $message = mail_archive_load_message($lid, $id);        $message = mail_archive_load_message($lid, $id);
# Line 1657  function mail_archive_index_header($lid, Line 1697  function mail_archive_index_header($lid,
1697    // we'll assume the message_id is everything within the first set of <>'s    // we'll assume the message_id is everything within the first set of <>'s
1698    preg_match("/<[^<^>]*/", $header->message_id, $message_id);    preg_match("/<[^<^>]*/", $header->message_id, $message_id);
1699    $message_id = ltrim($message_id[0], '<');    $message_id = ltrim($message_id[0], '<');
1700    /* the in_reply_to line can contain multiple tags that look like a message id, but only one    /* the in_reply_to line can contain multiple tags that look like a message id,
1701    ** of them should be valid.  We'll grab all of them, and hold onto them in the database until    ** but only one of them should be valid.  We'll grab all of them, and hold
1702    ** we find the good one.  When the "in_reply_tos" bit is set, we know that we're currently    ** onto them in the database until we find the good one.  When the
1703    ** holding onto multiple in_reply_to tags in the form of a comma seperated list.  As messages    ** "in_reply_tos" bit is set, we know that we're currently holding onto
1704    ** may arrive out of order, we can't assume we'll find the parent right now.    ** multiple in_reply_to tags in the form of a comma seperated list.  As
1705      ** messages may arrive out of order, we can't assume we'll find the parent
1706      ** right now.
1707    */    */
1708    preg_match_all("/<[^<^>]*/", $header->in_reply_to, $in_reply_tos);    preg_match_all("/<[^<^>]*/", $header->in_reply_to, $in_reply_tos);
1709    $in_reply_to = array();    $in_reply_to = array();
# Line 1670  function mail_archive_index_header($lid, Line 1712  function mail_archive_index_header($lid,
1712    }    }
1713    $in_reply_tos = count($in_reply_to) - 1;    $in_reply_tos = count($in_reply_to) - 1;
1714    if ($in_reply_tos < 1) {    if ($in_reply_tos < 1) {
1715      // we found 0 or 1 in_reply_to tags, so we don't need to store it in an array      /* we found 0 or 1 in_reply_to tags, so we don't need to store it in an
1716        ** array
1717        */
1718      $in_reply_to = implode(',', $in_reply_to);      $in_reply_to = implode(',', $in_reply_to);
1719      $in_reply_tos = 0;      $in_reply_tos = 0;
1720    }    }
1721    
1722    $duplicate = db_fetch_object(db_query('SELECT mid FROM {mail_archive_message_index} WHERE message_id = "%s" AND lid = %d', $message_id, $lid));    $duplicate = db_fetch_object(db_query('SELECT mid FROM {mail_archive_message_index} WHERE message_id = "%s" AND lid = %d', $message_id, $lid));
1723    if ($duplicate->mid) {    if ($duplicate->mid) {
1724      /* we've downloaded this message before, someone is re-indexing, ignore this message (and don't      /* we've downloaded this message before, someone is re-indexing, ignore
1725      ** increment messages_downloaded      ** this message (and don't increment messages_downloaded)
1726      */      */
1727      $mid = 0;      $mid = 0;
1728    }    }

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

  ViewVC Help
Powered by ViewVC 1.1.3