You should have received a copy of the GNU Public
License along with this package; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* these need to be up here so we can use the constants we define in functions. strange but true */
require '../lib/horde.lib';
require './lib/imp.lib'; /* IMPlib is the IMP function library */
function messageRange ($arr, $index, &$offset, &$beginIndex) {
$count = 200; // maybe make this configurable later
$half = $count/2;
if ($index < $half)
$start = 0;
else if (($index + $count) >= count($arr))
$start = max(0, count($arr) - $count);
else
$start = $index - $half;
$end = min($start + $count, count($arr));
$new = array();
for ($i = $start; $i < $end; $i++) {
$new[] = $arr[$i];
}
$offset = $start;
$beginIndex = $index - $start - 1;
return $new;
} // messageRange()
function snip ($address) {
$address = trim($address);
if ((substr($address, 0, 1) == '<') && (substr($address, -1) == '>')) {
$address = substr($address, 1, -1);
}
return $address;
}
function buildAddressString ($array, $color) {
global $default, $sess, $lang;
$string = '';
while (list(,$ob) = each($array)) {
if (isset($ob->personal)) $ob->personal = decode_mime_string($ob->personal);
else $ob->personal = '';
if (!isset($ob->mailbox)) $ob->mailbox = '';
if (!isset($ob->host)) $ob->host = '';
$addr = snip(imap_rfc822_write_address($ob->mailbox, $ob->host, $ob->personal));
$inner = snip(imap_rfc822_write_address($ob->mailbox, $ob->host, ''));
if (!empty($string)) $string .= ', ';
if ($default->minimum_popups) {
$string .= 'compose . '\'; return true;" onMouseOut="status=\'\';">' . htmlSpecialChars($addr) . '';
if ($default->user_use_addressbook && $default->use_db) {
$string .= '' . '
';
}
} // end while
return $string;
} // buildAddressString()
function buildMessage ($attachments, $msg) {
global $imp, $index, $default, $lang, $textparts, $images, $atc;
$j = 0;
reset($attachments);
while (list($ref, $mime) = each($attachments)) {
if (!$mime->header) {
mimeParse($mime);
if ($mime->type == TYPETEXT &&
($mime->SUBTYPE == 'plain' || $mime->SUBTYPE == 'enriched')
&& $mime->bytes > 0
// display only limited size parts inline
&& ($default->text_inline_size == 0 || $mime->size <= $default->text_inline_size)
&& ($mime->encoding == ENC7BIT || $mime->encoding == ENC8BIT || $mime->encoding == ENCQUOTEDPRINTABLE || $mime->encoding == ENCBASE64)
&& ($textparts == 0 || $default->text_parts_inline)) {
/* Safe to display, it is text */
/* get and format the main body part */
$tmsg = @imap_fetchbody($imp->stream, $index, $ref, FT_UID);
/* If it's a quoted-printable document, translate it into the right charset */
if ($mime->encoding == ENCQUOTEDPRINTABLE) {
$tmsg = imap_qprint($tmsg);
} elseif ($mime->encoding == ENCBASE64) {
$tmsg = imap_base64($tmsg);
}
if (strlen($tmsg) > 0) {
$tmsg = str_replace('', '', $tmsg); // make sure that the original message doesn't contain any capital /A tags, so we can assume we generated them
$tmsg = str_replace('\1://\2\3', $tmsg);
$tmsg = preg_replace('|[Mm][Aa][Ii][Ll][Tt][Oo]:(\s?)([\w+-=%&:_.~@]+[#\w+]*)|', 'mailto:\1\2', $tmsg);
$tmsg = htmlspecialchars($tmsg);
$tmsg = str_replace('<A href="', '', $tmsg);
$tmsg = str_replace('">','">', $tmsg);
$tmsg = str_replace('\');">', '\');">', $tmsg);
$tmsg = str_replace('</A>', '', $tmsg); // only reconvert capital /A tags - the ones we generated
}
$charset = $mime->charset;
if (strstr($charset, '1251')) {
$tmsg = convert_cyr_string($tmsg, 'w', 'k');
}
elseif (strstr($charset, '866')) {
$tmsg = convert_cyr_string($tmsg, 'a', 'k');
}
elseif (strstr($charset, '8859-5')) {
$tmsg = convert_cyr_string($tmsg, 'i', 'k');
}
elseif (stristr($charset, 'x-mac-cyrrilic')) {
$tmsg = convert_cyr_string($tmsg, 'm', 'k');
}
$tmsg = '
' . wrap_message($tmsg) . ''; if ($textparts > 0) { $msg = $msg . '
' . $func($mime) . ''; $textparts++; /* add it as an attachment link to download if this type is downloadable */ if (!empty($mime->conf['download']) && $default->inline_in_parts_list) { $atc .= mimeSummary($mime); } } else { if ($mime->ifid) $images[$mime->id] = $ref; $atc .= mimeSummary($mime); } } // end if() } // end while() return $msg; } require './lib/mimetypes.lib'; /* Mime handling routes */ require './config/defaults.php3'; /* Defaults configuration file */ require './config/html.php3'; require './config/mime.php3'; require './config/lang.php3'; $language = select_lang(); require './lib/postconf.php3'; require "./locale/$language/message.lang"; require './locale/local/message.lang'; require './config/lang.php3'; $this_client = new WebClient; error_reporting($default->error_level); page_open(array('sess' => 'HordeSession')); if (!isset($imp) || !is_object($imp)) { page_close(); header('Location: ' . $sess->url('login.php3?reason=logout')); exit; } $imp->unpickle(); $imp->authenticate(); $sorted = explode(':', $imp->msgl); if ($array_index == count($sorted)-1 || $array_index == 0 || (isset($actionID) && ($actionID == DELETE_MESSAGES || $actionID == MOVE_MESSAGES || $actionID == COPY_MESSAGES) && $array_index == count($sorted)-2)) { $sorted = imap_sort($imp->stream, $imp->sortby, $imp->sortdir, SE_UID); $num_msgs = count($sorted); $sorted = messageRange($sorted, $array_index + $imp->offset + 1, $offset, $array_index); $imp->msgl = implode(':', $sorted); $imp->offset = $offset; $imp->pickle(); } $msgindex = $array_index + $imp->offset; if (isset($actionID)) { switch ($actionID) { case NO_ACTION: break; case DELETE_MESSAGES: if ($index && $imp->mailbox) { if (!(@imap_delete($imp->stream, imap_msgno($imp->stream, $index)))) { $errormsg = $lang->delete_error; $array_index++; $msgindex++; $index = $sorted[$array_index]; } else { if ($imp->servtype == 'pop3') { // expunge the mailbox to actually delete the message, and then recalculate the message list imap_expunge($imp->stream); imap_close($imp->stream); $imp->authenticate(); $sorted = imap_sort($imp->stream, $imp->sortby, $imp->sortdir, SE_UID); $num_msgs = count($sorted); $sorted = messageRange($sorted, $array_index + $imp->offset + 1, $offset, $array_index); $imp->msgl = implode(':', $sorted); $imp->offset = $offset; $imp->pickle(); $index = $sorted[$array_index]; $msgindex = $array_index + $imp->offset; } else { $array_index++; $msgindex++; $index = $sorted[$array_index]; } } } break; case MOVE_MESSAGES: if (isset($index) && isset($targetMbox) && $index && $targetMbox) { $targetMbox = imap_utf7_encode($targetMbox); if (!(@imap_mail_copy($imp->stream, $index, $targetMbox, CP_UID|CP_MOVE))) { $status_string = $lang->move_error; $status_color = 'red'; } else { $plural = false; $status_string = $lang->success2($imp->label, imap_utf7_decode($targetMbox), 'moved', 1, $plural); $status_color = 'green'; $array_index++; $msgindex++; $index = $sorted[$array_index]; } } if (!isset($status_string)) { $plural = false; $status_string = $lang->move_error; $status_color = 'red'; } break; case COPY_MESSAGES: if (isset($index) && isset($targetMbox) && $targetMbox && $index) { $targetMbox = imap_utf7_encode($targetMbox); if (!@imap_mail_copy($imp->stream, $index, $targetMbox, CP_UID)) { $status_string = $lang->copy_error; $status_color = 'red'; } else { $plural = false; $status_string = $lang->success2($imp->label, imap_utf7_decode($targetMbox), 'copied', 1, $plural); $status_color = 'green'; $array_index++; $msgindex++; $index = $sorted[$array_index]; } } if (!isset($status_string)) { $plural = false; $status_string = $lang->copy_error; $status_color = 'red'; } break; } } page_close(); if ($default->user_use_folders) { $options = mailbox_list(true); } /* parse MIME header info */ $num_parts = 1; if ($structure = @imap_fetchstructure($imp->stream, $index, FT_UID)) { if (isset($structure->parts) && is_array($structure->parts)) $num_parts = count($structure->parts); } else { header('Location: ' . $sess->url('mailbox.php3')); exit; } require "$default->include_dir/doctype.inc"; $bodypart = 1; $textparts = 0; $atc = ''; $msg = ' '; $foo = false; $attachments = MimeParseStructure($structure, '', $foo); $msg = buildMessage($attachments, $msg); // handle multipart/related images. this should ideally go somewhere else, but it works here if (!empty($images)) { while (list($img, $id) = each($images)) { if (strlen($img) > 0) { if ($img[0] == '<') $img = substr($img, 1); if ($img[strlen($img)-1] == '>') $img = substr($img, 0, strlen($img)-1); $msg = str_replace("cid:$img", $sess->url('view.php3?actionID=' . VIEW_ATTACH) . '&index=' . $index . '&mailbox=' . urlencode($imp->mailbox) . '&bodypart=' . $id, $msg); } } } if ($default->view_message_source) { if (!isset($atc)) $atc = ''; $mime = new mime_part_data; $mime->set_type_full('message/source'); $atc .= '