Index: pontomail.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/pontomail/pontomail.module,v
retrieving revision 1.32
diff -u -r1.32 pontomail.module
--- pontomail.module 5 Oct 2006 21:25:50 -0000 1.32
+++ pontomail.module 16 Oct 2006 10:38:37 -0000
@@ -579,12 +579,9 @@
break;
}
- $max_pages = 200;
-
+ $max_pages = 50;
$WIDTH_LIMIT = 25;
-
-
$form['mail_actions']['act'] = array('#type' => 'select', '#title' => t('With Selected'),
'#options' => array(
'-' => t('Select an Action'),
@@ -596,85 +593,72 @@
$form['mail_actions']['send_action'] = array('#type' => 'submit', '#value' => 'Submit');
# Fetch the headers
- $mail_headers = $imap->get_headers($max_pages);
+ $imap->get_headers(arg(3), arg(4));
$form['mail_actions']['messages']['#tree'] = TRUE;
$form['mail_actions']['messages']['#theme'] = 'folder_view';
theme('add_style', drupal_get_path('module', 'pontomail') . '/pontomail.css');
-
+
+ $header = array(
+ array('data' => t('Select')),
+ array('data' => t('Subject'), 'field' => 'subject'),
+ array('data' => t('From'), 'field' => 'mfrom'),
+ array('data' => t('Date'), 'field' => 'mdate', 'sort' => 'desc'),
+ array('data' => t('Size'), 'field' => 'size')
+ );
+
$today = format_date(time(), 'custom', 'm.d.y');
- foreach($mail_headers as $key => $msg) {
+ $entries = pager_query("SELECT *
+ FROM {pontomail_messages}
+ WHERE uid = '%d' AND sid = '%d' AND folder = '%s'"
+ .tablesort_sql($header), $max_pages, 0, NULL, $user->uid, arg(3), arg(4));
+ while($row = db_fetch_object($entries)) {
$prefix = $suffix = "";
- if(!$msg->seen && !$msg->rescent) {
+ if(!$row->seen && !$row->rescent) {
$prefix = '
';
$suffix = '
';
}
- if($msg->deleted) {
+ if($row->deleted) {
$prefix = '';
$suffix = '
';
}
- $form['mail_actions']['messages'][$msg->uid]['mid'] = array('#type' => 'checkbox', '#default_value' => 0);
- if($msg->date != "") {
-
- if(format_date(strtotime($msg->date), 'custom','m.d.y') == $today) {
- $date = format_date(strtotime($msg->date), 'custom', 'g:i A');
+ $msg_link = 'pontomail/viewmailbox/accounts/' . arg(3) . '/' . arg(4) . '/' . str_replace('>', '', str_replace('<', '',$row->muid));
+ $form['mail_actions']['messages'][$row->muid]['mid'] = array('#type' => 'checkbox', '#default_value' => 0);
+ $form['mail_actions']['messages'][$row->muid]['subject'] = array(
+ '#value' => l(check_plain(strlen($row->subject) > $WIDTH_LIMIT ? substr($row->subject, 0,$WIDTH_LIMIT - 3) . '...' : $row->subject), $msg_link),
+ '#prefix' => $prefix, '#suffix' => $suffix
+ );
+ $form['mail_actions']['messages'][$row->muid]['from'] = array(
+ '#value' => check_plain(strlen($row->mfrom) > $WIDTH_LIMIT ? substr($row->mfrom, 0,$WIDTH_LIMIT - 3) . '...' : $row->mfrom),
+ '#prefix' => $prefix, '#suffix' => $suffix
+ );
+ if($row->mdate != "") {
+ if(format_date(strtotime($row->mdate), 'custom','m.d.y') == $today) {
+ $date = format_date(strtotime($row->mdate), 'custom', 'g:i A');
// strftime to deal with dates coming in rfc-2822 format
- $date = strftime("%I:%M %p", strtotime($msg->date));
+ $date = strftime("%I:%M %p", strtotime($row->mdate));
}
else {
- $date = format_date(strtotime($msg->date), 'custom', 'm.d.y');
+ $date = format_date(strtotime($row->mdate), 'custom', 'm.d.y');
}
}
- $msg_link = 'pontomail/viewmailbox/accounts/' . arg(3) . '/' . arg(4) . '/' . str_replace('>', '', str_replace('<', '',$msg->uid));
- $form['mail_actions']['messages'][$msg->uid]['date'] = array(
- '#value' => l($date, $msg_link),
- '#prefix' => $prefix, '#suffix' => $suffix
- );
- $form['mail_actions']['messages'][$msg->uid]['from'] = array(
- '#value' => l(strlen($msg->from) > $WIDTH_LIMIT ? substr($msg->from, 0,$WIDTH_LIMIT - 3) . '...' : $msg->from,
- $msg_link),
- '#prefix' => $prefix, '#suffix' => $suffix
- );
- $form['mail_actions']['messages'][$msg->uid]['subject'] = array(
- '#value' => strlen($msg->subject) > $WIDTH_LIMIT ? substr($msg->subject, 0,$WIDTH_LIMIT - 3) . '...' : $msg->subject,
+ $form['mail_actions']['messages'][$row->muid]['date'] = array(
+ '#value' => $date,
'#prefix' => $prefix, '#suffix' => $suffix
);
- $form['mail_actions']['messages'][$msg->uid]['size'] = array(
- '#value' => round(($msg->size/1024)) . ' KB',
+ $form['mail_actions']['messages'][$row->muid]['size'] = array(
+ '#value' => round(($row->size/1024)) . ' KB',
'#prefix' => $prefix, '#suffix' => $suffix
);
-
}
-
- /*
- foreach($mail_headers as $key => $msg) {
- $row = array();
+ $form['mail_actions']['messages']['#header'] = $header;
- $date = format_date(strtotime($msg->date), 'custom', 'm.d.y');
- $row[] = $form['mail_actions'][$msg->uid] = array('#type' => 'checkbox');
- $row[] = l($date, 'pontomail/viewmailbox/accounts/' . arg(3) . '/' . arg(4) . '/' . str_replace('>', '', str_replace('<', '',$msg->uid)));
- $row[] = strlen($msg->from) > $WIDTH_LIMIT ? substr($msg->from, 0,$WIDTH_LIMIT - 3) . '...' : $msg->from;
- $row[] = strlen($msg->subject) > $WIDTH_LIMIT ? substr($msg->subject, 0,$WIDTH_LIMIT - 3) . '...' : $msg->subject;
- $row[] = round(($msg->size/1024)) . ' KB';
-
- $rows[] = $row;
- }*/
-
- $rs = pager_query("SELECT * FROM {pontomail_pager_holder} WHERE uid = %d AND id = '%s'", $max_pages, 0, NULL, $user->uid, $imap->get_server_name());
$page .= drupal_get_form('folder_form', $form['mail_actions']); //theme('table', $headers, $rows);
$page = theme_pager(array(), $max_pages) . $page;
return $page;
}
function theme_folder_view($form) {
- $output = "";
- $headers = array(
- array('data' => t('Select')),
- array('data' => t('Date')),
- array('data' => t('From')),
- array('data' => t('Subject')),
- array('data' => t('Size'))
- );
-
+ $header = $form['#header'];
foreach(element_children($form) as $key) {
$row = array();
foreach($form[$key] as $inner_key => $item) {
@@ -688,7 +672,7 @@
$rows[] = $row;
}
- $output = theme('table', $headers, $rows);
+ $output = theme('table', $header, $rows);
return $output;
}
@@ -871,9 +855,9 @@
format_date(strtotime($message_obj->headers->MailDate), 'custom', 'F j, Y ')
. strftime("%I:%M %p", strtotime($message_obj->headers->MailDate))
. "";
- $page .= "
From: " . htmlspecialchars($message_obj->headers->fromaddress) . "";
- $page .= "
To: " . htmlspecialchars($message_obj->headers->toaddress) . "";
- $page .= "
Subject: " . htmlspecialchars($message_obj->headers->Subject) . "";
+ $page .= "
From: " . htmlspecialchars(decode_header($message_obj->headers->fromaddress)) . "";
+ $page .= "
To: " . htmlspecialchars(decode_header($message_obj->headers->toaddress)) . "";
+ $page .= "
Subject: " . htmlspecialchars(decode_header($message_obj->headers->Subject)) . "";
$page .= "
";
# Attachement Grouping
@@ -1565,5 +1549,67 @@
return '\n";
}
+function decode_header($input) {
+ $out = '';
+
+ $pos = strpos($input, '=?');
+ if ($pos !== false) {
+ $out = substr($input, 0, $pos);
+
+ $end_cs_pos = strpos($input, "?", $pos+2);
+ $end_en_pos = strpos($input, "?", $end_cs_pos+1);
+ $end_pos = strpos($input, "?=", $end_en_pos+1);
+
+ $encstr = substr($input, $pos+2, ($end_pos-$pos-2));
+ $rest = substr($input, $end_pos+2);
+
+ $out .= _decode_mime_string_part($encstr);
+ $out .= decode_header($rest);
+ return $out;
+ }
+ else {
+ return $input;
+ }
+}
+
+function _decode_mime_string_part($str) {
+ $a = explode('?', $str);
+ $count = count($a);
+
+ // should be in format "charset?encoding?base64_string"
+ if ($count >= 3) {
+ for ($i=2; $i<$count; $i++) {
+ $rest.=$a[$i];
+ }
+
+ if (($a[1]=="B")||($a[1]=="b")) {
+ $rest = base64_decode($rest);
+ }
+ else if (($a[1]=="Q")||($a[1]=="q")) {
+ $rest = str_replace("_", " ", $rest);
+ $rest = quoted_printable_decode($rest);
+ }
+ return charset_convert($rest, $a[0]);
+ }
+ else {
+ return $str; // we dont' know what to do with this
+ }
+}
+
+function charset_convert($str, $from, $to=NULL) {
+ $from = strtoupper($from);
+ $to = $to==NULL ? 'UTF-8' : strtoupper($to);
+
+ if ($from==$to) {
+ return $str;
+ }
+
+ // convert charset using iconv module
+ if (function_exists('iconv')) {
+ return iconv($from, $to, $str);
+ }
+
+ return $str;
+}
?>
Index: pontomail_sendmail.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/pontomail/pontomail_sendmail.module,v
retrieving revision 1.25
diff -u -r1.25 pontomail_sendmail.module
--- pontomail_sendmail.module 5 Oct 2006 08:59:41 -0000 1.25
+++ pontomail_sendmail.module 16 Oct 2006 10:38:38 -0000
@@ -361,6 +361,7 @@
$form['sid'] = array('#type' => 'hidden', '#value' => $sid);
}
$form['from'] = array('#type' => 'item', '#title' => t('From'), '#value' => $user_email);
+ $from = ($fwd) ? '' : decode_header($from);
$form['to'] = array('#type' => 'textfield',
'#title' => t('To'),
'#default_value' => $from,
@@ -369,7 +370,7 @@
'#description' => t('Seperate multiple email addresses with a comma (,). Also,
please not that entires that were found via LDAP and are not local to Drupal will be show with
an * in front of them. This is only availiable if you have javascript enabled.'));
- $form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#maxlength' => 50, '#required' => TRUE, '#default_value' => $subject);
+ $form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#maxlength' => 50, '#required' => TRUE, '#default_value' => decode_header($subject));
$form['message'] = array('#type' => 'textarea',
'#title' => t('Message'),
'#rows' => 15, '#required' => TRUE,
Index: IMAPService.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/pontomail/IMAPService.inc,v
retrieving revision 1.17
diff -u -r1.17 IMAPService.inc
--- IMAPService.inc 21 Aug 2006 08:58:01 -0000 1.17
+++ IMAPService.inc 16 Oct 2006 10:38:38 -0000
@@ -156,30 +156,24 @@
}
- function get_headers($max_pages = 50) {
+ function get_headers($sid, $folder) {
global $user;
- $sorted_msgs=imap_sort($this->mbox,SORTARRIVAL,1);
- # Respect Paging from Drupal
- if($_GET['page'] != "") {
- $max = ceil($sorted_msgs[0] - (($_GET['page'] + 1) * $max_pages));
- $max = $max < 0 ? $max + $max_pages : $max;
- }
- else {
- $max = $sorted_msgs[0];
- }
- $min = $max > $max_pages ? $max - $max_pages - 1 : $sorted_msgs[(count($sorted_msgs) - 1)];
- $headers = imap_fetch_overview($this->mbox, $max.':'.$min);
- if(!$headers) {
- $erros = imap_errors();
- // TODO Place this error in the watch dog.
- return array();
- }
- $headers = array_reverse($headers);
- db_query("DELETE FROM {pontomail_pager_holder} WHERE uid = %d AND id = %d", $user->uid, $this->server);
- for($i = 0; $i < $sorted_msgs[0]; $i++) {
- db_query("INSERT INTO {pontomail_pager_holder} (uid, id) VALUES(%d, '%s')", $user->uid, $this->server);
+
+ $months = array('Jan' => '01', 'Feb' => '02', 'Mar' => '03', 'Apr' => '04', 'May' => '05', 'Jun' => '06', 'Jul' => '07', 'Aug' => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' => '12');
+ $mc=imap_check($this->mbox);
+ $mn=$mc->Nmsgs;
+ db_query("DELETE FROM {pontomail_messages} WHERE uid = %d AND sid = %d AND folder = '%s'", $user->uid, $sid, $folder);
+ $h = imap_fetch_overview($this->mbox, "1:$mn", 0);
+ foreach ($h as $header) {
+ $subject = decode_header($header->subject);
+ $subject = ($subject) ? $subject : '['.t('no subject').']';
+ $date = preg_replace('/\S+,\s+/', '', $header->date);
+ $date = explode(" ", $date);
+ $timestamp = $date[2]."-".$months[$date[1]]."-".$date[0]." ".$date[3];
+ $from = preg_replace('/[<>"]/', '', decode_header($header->from));
+ $from = preg_replace('/(.*)\s+\S+/', '\1', $from);
+ db_query("INSERT INTO {pontomail_messages} (uid, sid, folder, muid, subject, mfrom, mto, mdate, size, recent, flagged, answered, deleted, seen, draft) VALUES(%d, %d, '%s', %d, '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, %d, %d)", $user->uid, $sid, $folder, $header->uid, $subject, $from, $header->to, $timestamp, $header->size, $header->recent, $header->flagged, $header->answered, $header->deleted, $header->seen, $header->draft);
}
- return $headers;
}
function num_new_msgs($folder = "") {