- $message = sqimap_get_message($imapConnection, $id, $mailbox);
- $orig_header = $message->header;
- if ($ent_num) {
- $message = getEntity($message, $ent_num);
- }
- if ($message->header->type0 == 'text' ||
- $message->header->type1 == 'message') {
- if ($ent_num) {
- $body = decodeBody(
- mime_fetch_body($imapConnection, $id, $ent_num),
- $message->header->encoding);
- } else {
- $body = decodeBody(
- mime_fetch_body($imapConnection, $id, 1),
- $message->header->encoding);
- }
- }
- else {
- $body = '';
- }
-
- if ($message->header->type1 == 'html') {
- $body = strip_tags($body);
- }
-
- sqUnWordWrap($body);
- $body_ary = explode("\n", $body);
- $i = count($body_ary) - 1;
- while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) {
- unset($body_ary[$i]);
- $i --;
- }
- $body = '';
- for ($i=0; isset($body_ary[$i]); $i++) {
- if ($reply_id) {
- if (ereg('^[ >]+', $body_ary[$i])) {
- $body_ary[$i] = '>' . $body_ary[$i];
- }
- else {
- $body_ary[$i] = '> ' . $body_ary[$i];
- }
- }
- if (!$draft_id) {
- sqWordWrap($body_ary[$i], $editor_size - 1);
- }
- $body .= $body_ary[$i] . "\n";
- unset($body_ary[$i]);
- }
- if ($forward_id) {
- $bodyTop = '-------- ' . _("Original Message") . " --------\n" .
- _("Subject") . ': ' . $orig_header->subject . "\n" .
- _("From") . ': ' . $orig_header->from . "\n" .
- _("Date") . ': ' .
- getLongDateString( $orig_header->date ). "\n" .
- _("To") . ': ' . $orig_header->to[0] . "\n";
- if (count($orig_header->to) > 1) {
- for ($x=1; $x < count($orig_header->to); $x++) {
- $bodyTop .= ' ' . $orig_header->to[$x] . "\n";
- }
- }
- $bodyTop .= "\n";
- $body = $bodyTop . $body;
- }
- elseif ($reply_id) {
- $orig_from = decodeHeader($orig_header->from);
- $body = getReplyCitation($orig_from) . $body;
- }
-
- return;
- }
-
- if (!$send_to) {
- $send_to = sqimap_find_email($send_to);
- }
-
- /* This formats a CC string if they hit "reply all" */
- if ($send_to_cc != '') {
- $send_to_cc = ereg_replace('"[^"]*"', '', $send_to_cc);
- $send_to_cc = ereg_replace(';', ',', $send_to_cc);
- $sendcc = explode(',', $send_to_cc);
- $send_to_cc = '';
-
- for ($i = 0; $i < count($sendcc); $i++) {
- $sendcc[$i] = trim($sendcc[$i]);
- if ($sendcc[$i] == '') {
- continue;
- }
-
- $sendcc[$i] = sqimap_find_email($sendcc[$i]);
- $whofrom = sqimap_find_displayable_name($msg['HEADER']['FROM']);
- $whoreplyto = sqimap_find_email($msg['HEADER']['REPLYTO']);
-
- if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
- (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
- (trim($sendcc[$i]) != '')) {
- $send_to_cc .= trim($sendcc[$i]) . ', ';
- }
- }
- $send_to_cc = trim($send_to_cc);
- if (substr($send_to_cc, -1) == ',') {
- $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
- }
- }
+ $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
+ $body = '';
+ if ($passed_ent_id) {
+ /* redefine the messsage in case of message/rfc822 */
+ $message = $message->getEntity($passed_ent_id);
+ /* message is an entity which contains the envelope and type0=message
+ * and type1=rfc822. The actual entities are childs from
+ * $message->entities[0]. That's where the encoding and is located
+ */
+
+ $entities = $message->entities[0]->findDisplayEntity
+ (array(), $alt_order = array('text/plain'));
+ if (!count($entities)) {
+ $entities = $message->entities[0]->findDisplayEntity
+ (array(), $alt_order = array('text/plain','html/plain'));
+ }
+ $orig_header = $message->header; /* here is the envelope located */
+ /* redefine the message for picking up the attachments */
+ $message = $message->entities[0];
+
+ } else {
+ $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
+ if (!count($entities)) {
+ $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
+ }
+ $orig_header = $message->header;
+ }
+ $encoding = $message->header->encoding;
+ $type0 = $message->type0;
+ $type1 = $message->type1;
+
+ foreach ($entities as $ent) {
+ $bodypart = decodeBody(
+ mime_fetch_body($imapConnection, $passed_id, $ent),
+ $encoding);
+ if ($type1 == 'html') {
+ $bodypart = strip_tags($bodypart);
+ }
+ $body .= $bodypart;
+ }
+ if ($default_use_priority) {
+ $mailprio = substr($orig_header->priority,0,1);
+ } else {
+ $mailprio = '';
+ }
+ ClearAttachments($session);
+ switch ($action) {
+ case ('draft'):
+ $use_signature = FALSE;
+ $send_to = $orig_header->getAddr_s('to');
+ $send_to_cc = $orig_header->getAddr_s('cc');
+ $send_to_bcc = $orig_header->getAddr_s('bcc');
+ $subject = $orig_header->subject;
+
+ $body_ary = explode("\n", $body);
+ $cnt = count($body_ary) ;
+ $body = '';
+ for ($i=0; $i < $cnt; $i++) {
+ if (!ereg("^[>\\s]*$", $body_ary[$i])) {
+ sqWordWrap($body_ary[$i], $editor_size );
+ $body .= $body_ary[$i] . "\n";
+ }
+ unset($body_ary[$i]);
+ }
+ sqUnWordWrap($body);
+ getAttachments($message, $session, $passed_id, $entities, $imapConnection);
+ break;
+ case ('edit_as_new'):
+ $send_to = $orig_header->getAddr_s('to');
+ $send_to_cc = $orig_header->getAddr_s('cc');
+ $send_to_bcc = $orig_header->getAddr_s('bcc');
+ $subject = $orig_header->subject;
+ $mailprio = $orig_header->priority;
+ getAttachments($message, $session, $passed_id, $entities, $imapConnection);
+ sqUnWordWrap($body);
+ break;
+ case ('forward'):
+ $send_to = '';
+ $orig_from = $orig_header->from->getAddress();
+ $subject = $orig_header->subject;
+ if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
+ (substr(strtolower($subject), 0, 5) != '[fwd:') &&
+ (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
+ $subject = '[Fwd: ' . $subject . ']';
+ }
+ $body = getforwardHeader($orig_header) . $body;
+ sqUnWordWrap($body);
+ getAttachments($message, $session, $passed_id, $entities, $imapConnection);
+ break;
+ case ('reply' || 'reply_all'):
+ $send_to = $orig_header->reply_to;
+ if ($send_to) {
+ $send_to = $send_to->getAddress();
+ } else {
+ $send_to = $orig_header->from->getAddress();
+ }
+ $orig_from = $orig_header->from->getAddress();
+ $subject = $orig_header->subject;
+ $subject = str_replace('"', "'", $subject);
+ $subject = trim($subject);
+ if (substr(strtolower($subject), 0, 3) != 're:') {
+ $subject = 'Re: ' . $subject;
+ }
+ if ($action == 'reply_all') {
+ $send_to_cc = replyAllString($orig_header);
+ }
+ /* this corrects some wrapping/quoting problems on replies */
+ $rewrap_body = explode("\n", $body);
+ $body = getReplyCitation($orig_header->from->personal);
+ $cnt = count($rewrap_body);
+ for ($i=0;$i<$cnt;$i++) {
+ sqWordWrap($rewrap_body[$i], ($editor_size - 2));
+ if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
+ $gt = $matches[1];
+ $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
+ } else {
+ $body .= '> ' . $rewrap_body[$i] . "\n";
+ }
+ unset($rewrap_body[$i]);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ $ret = array(
+ 'send_to' => $send_to,
+ 'send_to_cc' => $send_to_cc,
+ 'send_to_bcc' => $send_to_bcc,
+ 'subject' => $subject,
+ 'mailprio' => $mailprio,
+ 'body' => $body
+ );
+
+ return ($ret);