- $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];
+ $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";