function createMessage(&$_mailObject, $_formData, $_identity, $_signature = false) { $bofelamimail =& CreateObject('felamimail.bofelamimail', $this->displayCharset); $userLang = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang']; $langFile = PHPGW_SERVER_ROOT . "/phpgwapi/setup/phpmailer.lang-{$userLang}.php"; if (file_exists($langFile)) { $_mailObject->SetLanguage($userLang, PHPGW_SERVER_ROOT . "/phpgwapi/setup/"); } else { $_mailObject->SetLanguage("en", PHPGW_SERVER_ROOT . "/phpgwapi/setup/"); } $_mailObject->PluginDir = PHPGW_SERVER_ROOT . "/phpgwapi/inc/phpmailer/"; $activeMailProfile = $this->preferences->getIdentity(0); $_mailObject->IsSMTP(); $_mailObject->CharSet = $this->displayCharset; // you need to set the sender, if you work with different identities, since most smtp servers, dont allow // sending in the name of someone else $_mailObject->Sender = $activeMailProfile->emailAddress; $_mailObject->From = $_identity->emailAddress; $_mailObject->FromName = $_mailObject->EncodeHeader($_identity->realName); $_mailObject->Priority = $_formData['priority']; $_mailObject->Encoding = 'quoted-printable'; $_mailObject->AddCustomHeader('X-Mailer: FeLaMiMail'); if (isset($this->sessionData['in-reply-to'])) { $_mailObject->AddCustomHeader('In-Reply-To: ' . $this->sessionData['in-reply-to']); } if ($_formData['disposition']) { $_mailObject->AddCustomHeader('Disposition-Notification-To: ' . $_identity->emailAddress); } if (!empty($_identity->organization)) { #$_mailObject->AddCustomHeader('Organization: '. $bofelamimail->encodeHeader($_identity->organization, 'q')); $_mailObject->AddCustomHeader('Organization: ' . $_identity->organization); } foreach ((array) $_formData['to'] as $address) { $address_array = imap_rfc822_parse_adrlist($address, ''); foreach ((array) $address_array as $addressObject) { $emailAddress = $addressObject->mailbox . (!empty($addressObject->host) ? '@' . $addressObject->host : ''); #$emailName = $bofelamimail->encodeHeader($addressObject->personal, 'q'); #$_mailObject->AddAddress($emailAddress, $emailName); $_mailObject->AddAddress($emailAddress, $addressObject->personal); } } foreach ((array) $_formData['cc'] as $address) { $address_array = imap_rfc822_parse_adrlist($address, ''); foreach ((array) $address_array as $addressObject) { $emailAddress = $addressObject->mailbox . (!empty($addressObject->host) ? '@' . $addressObject->host : ''); #$emailName = $bofelamimail->encodeHeader($addressObject->personal, 'q'); #$_mailObject->AddCC($emailAddress, $emailName); $_mailObject->AddCC($emailAddress, $addressObject->personal); } } foreach ((array) $_formData['bcc'] as $address) { $address_array = imap_rfc822_parse_adrlist($address, ''); foreach ((array) $address_array as $addressObject) { $emailAddress = $addressObject->mailbox . (!empty($addressObject->host) ? '@' . $addressObject->host : ''); #$emailName = $bofelamimail->encodeHeader($addressObject->personal, 'q'); #$_mailObject->AddBCC($emailAddress, $emailName); $_mailObject->AddBCC($emailAddress, $addressObject->personal); } } foreach ((array) $_formData['replyto'] as $address) { $address_array = imap_rfc822_parse_adrlist($address, ''); foreach ((array) $address_array as $addressObject) { $emailAddress = $addressObject->mailbox . (!empty($addressObject->host) ? '@' . $addressObject->host : ''); #$emailName = $bofelamimail->encodeHeader($addressObject->personal, 'q'); #$_mailObject->AddBCC($emailAddress, $emailName); $_mailObject->AddReplyto($emailAddress, $addressObject->personal); } } $_mailObject->WordWrap = 76; #$_mailObject->Subject = $bofelamimail->encodeHeader($_formData['subject'], 'q'); $_mailObject->Subject = $_formData['subject']; #$realCharset = mb_detect_encoding($_formData['body'] . 'a' , strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'); #error_log("bocompose::createMessage:".$realCharset); // this should never happen since we come from the edit dialog if (bofelamimail::detect_qp($_formData['body'])) { error_log("Error: bocompose::createMessage found QUOTED-PRINTABLE while Composing Message. Charset:{$realCharset} Message:" . print_r($_formData['body'], true)); $_formData['body'] = preg_replace('/=\\r\\n/', '', $_formData['body']); $_formData['body'] = quoted_printable_decode($_formData['body']); } #if ($realCharset != $this->displayCharset) error_log("Error: bocompose::createMessage found Charset ($realCharset) differs from DisplayCharset (".$this->displayCharset.")"); if ($_formData['mimeType'] == 'html') { $_mailObject->IsHTML(true); if (!empty($_signature->fm_signature)) { #$_mailObject->Body = array($_formData['body'], $_signature['signature']); $_mailObject->Body = $_formData['body'] . '<hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">' . $_signature->fm_signature; $_mailObject->AltBody = $this->convertHTMLToText($_formData['body']) . "\r\n--\r\n" . $this->convertHTMLToText($_signature->fm_signature); #print "<pre>$_mailObject->AltBody</pre>"; #print htmlentities($_signature['signature']); } else { $_mailObject->Body = $_formData['body']; $_mailObject->AltBody = $this->convertHTMLToText($_formData['body']); } } else { $_mailObject->IsHTML(false); $_mailObject->Body = $this->convertHTMLToText($_formData['body']); if (!empty($_signature->fm_signature)) { $_mailObject->Body .= "\r\n--\r\n" . $this->convertHTMLToText($_signature->fm_signature); } } // add the attachments $bofelamimail->openConnection(); foreach ((array) $this->sessionData['attachments'] as $attachment) { if (!empty($attachment['uid']) && !empty($attachment['folder'])) { switch ($attachment['type']) { case 'MESSAGE/RFC822': $rawHeader = ''; $bofelamimail->reopen($attachment['folder']); if (isset($attachment['partID'])) { $rawHeader = $bofelamimail->getMessageRawHeader($attachment['uid'], $attachment['partID']); } $rawBody = $bofelamimail->getMessageRawBody($attachment['uid'], $attachment['partID']); $_mailObject->AddStringAttachment($rawHeader . $rawBody, $attachment['name'], '7bit', 'message/rfc822'); break; default: $bofelamimail->reopen($attachment['folder']); $attachmentData = $bofelamimail->getAttachment($attachment['uid'], $attachment['partID']); $_mailObject->AddStringAttachment($attachmentData['attachment'], $attachment['name'], 'base64', $attachment['type']); break; } } else { $_mailObject->AddAttachment($attachment['file'], $attachment['name'], 'base64', $attachment['type']); } } $bofelamimail->closeConnection(); }
function &getdisplayableBody($_bodyParts) { $bodyParts = $_bodyParts; $webserverURL = $GLOBALS['phpgw_info']['server']['webserver_url']; $nonDisplayAbleCharacters = array('[\\016]', '[\\017]', '[\\020]', '[\\021]', '[\\022]', '[\\023]', '[\\024]', '[\\025]', '[\\026]', '[\\027]', '[\\030]', '[\\031]', '[\\032]', '[\\033]', '[\\034]', '[\\035]', '[\\036]', '[\\037]'); $body = ''; #_debug_array($bodyParts); exit; foreach ($bodyParts as $singleBodyPart) { if (!empty($body)) { $body .= '<hr style="border:dotted 1px silver;">'; } #_debug_array($singleBodyPart['charSet']); $singleBodyPart['body'] = $this->botranslation->convert($singleBodyPart['body'], strtolower($singleBodyPart['charSet'])); //error_log($singleBodyPart['body']); #$CharSetUsed = mb_detect_encoding($singleBodyPart['body'] . 'a' , strtoupper($singleBodyPart['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'); if ($singleBodyPart['mimeType'] == 'text/plain') { $newBody = $singleBodyPart['body']; $newBody = @htmlentities($singleBodyPart['body'], ENT_QUOTES, strtoupper($this->displayCharset)); // if the conversion to htmlentities fails somehow, try without specifying the charset, which defaults to iso- if (empty($newBody)) { $newBody = htmlentities($singleBodyPart['body'], ENT_QUOTES); } #$newBody = $this->bofelamimail->wordwrap($newBody, 90, "\n"); // search http[s] links and make them as links available again // to understand what's going on here, have a look at // http://www.php.net/manual/en/function.preg-replace.php // create links for websites $newBody = preg_replace("/((http(s?):\\/\\/)|(www\\.))([\\w,\\-,\\/,\\?,\\=,\\.,&,!\n,!>,\\%,@,\\*,#,:,~,\\+]+)/ie", "'<a href=\"{$webserverURL}/redirect.php?go='.@htmlentities(urlencode('http\$3://\$4\$5'),ENT_QUOTES,\"{$this->displayCharset}\").'\" target=\"_blank\"><font color=\"blue\">\$2\$4\$5</font></a>'", $newBody); // create links for ftp sites $newBody = preg_replace("/((ftp:\\/\\/)|(ftp\\.))([\\w\\.,-.,\\/.,\\?.,\\=.,&]+)/i", "<a href=\"ftp://\$3\$4\" target=\"_blank\"><font color=\"blue\">ftp://\$3\$4</font></a>", $newBody); // create links for email addresses $this->parseEmail($newBody); $newBody = $this->highlightQuotes($newBody); $newBody = nl2br($newBody); } else { $newBody = $singleBodyPart['body']; $newBody = $this->highlightQuotes($newBody); bofelamimail::getCleanHTML($newBody); // create links for websites #$newBody = preg_replace("/(?<!\>)((http(s?):\/\/)|(www\.))([\w,\-,\/,\?,\=,\.,&,!\n,\%,@,\*,#,:,~,\+]+)/ie", # "'<a href=\"$webserverURL/redirect.php?go='.htmlentities(urlencode('http$3://$4$5'),ENT_QUOTES,\"$this->displayCharset\").'\" target=\"_blank\"><font color=\"blue\">$2$4$5</font></a>'", $newBody); $newBody = preg_replace("/(?<!>|\\/|\")((http(s?):\\/\\/)|(www\\.))([\\w,\\-,\\/,\\?,\\=,\\.,&,!\n,\\%,@,\\*,#,:,~,\\+]+)/ie", "'<a href=\"{$webserverURL}/redirect.php?go='.@htmlentities(urlencode('http\$3://\$4\$5'),ENT_QUOTES,\"{$this->displayCharset}\").'\" target=\"_blank\"><font color=\"blue\">\$2\$4\$5</font></a>'", $newBody); // create links for websites $newBody = preg_replace("/href=(\"|\\')((http(s?):\\/\\/)|(www\\.))([\\w,\\-,\\/,\\?,\\=,\\.,&,!\n,\\%,@,\\(,\\),\\*,#,:,~,\\+]+)(\"|\\')/ie", "'href=\"{$webserverURL}/redirect.php?go='.@htmlentities(urlencode('http\$4://\$5\$6'),ENT_QUOTES,\"{$this->displayCharset}\").'\" target=\"_blank\"'", $newBody); // create links for ftp sites $newBody = preg_replace("/href=(\"|\\')((ftp:\\/\\/)|(ftp\\.))([\\w\\.,-.,\\/.,\\?.,\\=.,&]+)(\"|\\')/i", "href=\"ftp://\$4\$5\" target=\"_blank\"", $newBody); // create links for inline images $linkData = array('menuaction' => 'felamimail.uidisplay.displayImage', 'uid' => $this->uid, 'mailbox' => base64_encode($this->mailbox)); $imageURL = $GLOBALS['phpgw']->link('/index.php', $linkData); $newBody = preg_replace("/(\"|\\')cid:(.*)(\"|\\')/iUe", "'\"{$imageURL}&cid='.base64_encode('\$2').'&partID='.urlencode({$this->partID}).'\"'", $newBody); // create links for email addresses $linkData = array('menuaction' => 'felamimail.uicompose.compose'); $link = $GLOBALS['phpgw']->link('/index.php', $linkData); $newBody = preg_replace("/href=(\"|\\')mailto:([\\w,\\-,\\/,\\?,\\=,\\.,&,!\n,\\%,@,\\*,#,:,~,\\+]+)(\"|\\')/ie", "'href=\"{$link}&send_to='.base64_encode('\$2').'\"'", $newBody); #print "<pre>".htmlentities($newBody)."</pre><hr>"; // replace emails within the text with clickable links. $this->parseEmail($newBody); } $body .= $newBody; #print "<hr><pre>$body</pre><hr>"; } // create links for windows shares // \\\\\\\\ == '\\' in real life!! :) $body = preg_replace("/(\\\\\\\\)([\\w,\\\\,-]+)/i", "<a href=\"file:\$1\$2\" target=\"_blank\"><font color=\"blue\">\$1\$2</font></a>", $body); $body = preg_replace($nonDisplayAbleCharacters, '', $body); return $body; }
function __construct($_displayCharset = 'utf-8') { $this->restoreSessionData(); // FIXME: this->foldername seems to be unused //$this->foldername = $this->sessionData['mailbox']; $this->accountid = $GLOBALS['phpgw_info']['user']['account_id']; $this->bopreferences =& CreateObject('felamimail.bopreferences'); $this->sofelamimail =& CreateObject('felamimail.sofelamimail'); $this->botranslation =& CreateObject('felamimail.translation'); $this->mailPreferences = $this->bopreferences->getPreferences(); $this->icServer = $this->mailPreferences->getIncomingServer(0); $this->ogServer = $this->mailPreferences->getOutgoingServer(0); #_debug_array($this->mailPreferences); $this->imapBaseDir = ''; self::$displayCharset = $_displayCharset; if (function_exists(mb_decode_mimeheader)) { mb_internal_encoding(self::$displayCharset); } // set some defaults if (empty($this->sessionData)) { // this should be under user preferences // sessionData empty // no filter active $this->sessionData['activeFilter'] = "-1"; // default mailbox INBOX $this->sessionData['mailbox'] = "INBOX"; // default start message $this->sessionData['startMessage'] = 1; // default mailbox for preferences pages $this->sessionData['preferences']['mailbox'] = "INBOX"; $this->sessionData['messageFilter'] = array('string' => '', 'type' => 'quick', 'status' => 'any'); // default sorting switch ($GLOBALS['phpgw_info']['user']['preferences']['felamimail']['sortOrder']) { case 1: $this->sessionData['sort'] = SORTDATE; $this->sessionData['sortReverse'] = false; break; case 2: $this->sessionData['sort'] = SORTFROM; $this->sessionData['sortReverse'] = true; break; case 3: $this->sessionData['sort'] = SORTFROM; $this->sessionData['sortReverse'] = false; break; case 4: $this->sessionData['sort'] = SORTSUBJECT; $this->sessionData['sortReverse'] = true; break; case 5: $this->sessionData['sort'] = SORTSUBJECT; $this->sessionData['sortReverse'] = false; break; case 6: $this->sessionData['sort'] = SORTSIZE; $this->sessionData['sortReverse'] = true; break; case 7: $this->sessionData['sort'] = SORTSIZE; $this->sessionData['sortReverse'] = false; break; default: $this->sessionData['sort'] = SORTDATE; $this->sessionData['sortReverse'] = true; break; } $this->saveSessionData(); } if (function_exists('mb_convert_encoding')) { $this->mbAvailable = TRUE; } $this->htmlOptions = $this->mailPreferences->preferences['htmlOptions']; }
static function mergeProfileData($mergeInTo, $toMerge) { if (is_array($toMerge) && count($toMerge) > 0) { $allkeys = array_unique(array_keys($mergeInTo) + array_keys($toMerge)); foreach ($allkeys as $i => $key) { if (!array_key_exists($key, $mergeInTo) && array_key_exists($key, $toMerge) && !empty($toMerge[$key])) { $mergeInTo[$key] = $toMerge[$key]; } else { if (array_key_exists($key, $toMerge) && !empty($toMerge[$key])) { switch ($key) { case 'ea_imap_server': case 'ea_imap_type': case 'ea_imap_port': case 'ea_imap_tsl_encryption': case 'ea_imap_tsl_auth': if (strlen($toMerge['ea_imap_server']) > 0) { $mergeInTo[$key] = $toMerge[$key]; } break; case 'ea_smtp_port': case 'ea_smtp_type': case 'ea_smtp_server': if (strlen($toMerge['ea_smtp_server']) > 0) { $mergeInTo[$key] = $toMerge[$key]; } break; case 'ea_default_signature': $testVal = $toMerge['ea_default_signature']; bofelamimail::getCleanHTML($testVal); if (strlen($testVal) > 10 || $testVal != '<br>' || $testVal != '<br />') { $mergeInTo[$key] = $toMerge[$key]; } break; default: $mergeInTo[$key] = $toMerge[$key]; } } } } } return $mergeInTo; }