|
iTx Technologies offre gratuitement
|
||
[Vue sommaire] [Imprimer] [Vue textuelle]
1 <?php 2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 3 /********************************************************************************* 4 * SugarCRM is a customer relationship management program developed by 5 * SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc. 6 * 7 * This program is free software; you can redistribute it and/or modify it under 8 * the terms of the GNU General Public License version 3 as published by the 9 * Free Software Foundation with the addition of the following permission added 10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK 11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY 12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 13 * 14 * This program is distributed in the hope that it will be useful, but WITHOUT 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 * details. 18 * 19 * You should have received a copy of the GNU General Public License along with 20 * this program; if not, see http://www.gnu.org/licenses or write to the Free 21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 22 * 02110-1301 USA. 23 * 24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, 25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com. 26 * 27 * The interactive user interfaces in modified source and object code versions 28 * of this program must display Appropriate Legal Notices, as required under 29 * Section 5 of the GNU General Public License version 3. 30 * 31 * In accordance with Section 7(b) of the GNU General Public License version 3, 32 * these Appropriate Legal Notices must retain the display of the "Powered by 33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for 34 * technical reasons, the Appropriate Legal Notices must display the words 35 * "Powered by SugarCRM". 36 ********************************************************************************/ 37 /********************************************************************************* 38 39 * Description: TODO: To be written. 40 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 41 * All Rights Reserved. 42 * Contributor(s): ______________________________________.. 43 ********************************************************************************/ 44 require_once ('include/phpmailer/class.phpmailer.php'); 45 require_once ('include/OutboundEmail/OutboundEmail.php'); 46 47 48 class SugarPHPMailer extends PHPMailer { 49 var $oe; // OutboundEmail 50 var $protocol = "tcp://"; 51 var $preppedForOutbound = false; 52 var $disclosureEnabled; 53 var $disclosureText; 54 var $isHostEmpty = false; 55 var $opensslOpened = true; 56 57 /** 58 * Sole constructor 59 */ 60 function SugarPHPMailer() { 61 global $locale; 62 global $current_user; 63 global $sugar_config; 64 65 $admin = new Administration(); 66 $admin->retrieveSettings(); 67 68 if(isset($admin->settings['disclosure_enable']) && !empty($admin->settings['disclosure_enable'])) { 69 $this->disclosureEnabled = true; 70 $this->disclosureText = $admin->settings['disclosure_text']; 71 } 72 73 $this->oe = new OutboundEmail(); 74 $this->oe->getUserMailerSettings($current_user); 75 76 $this->SetLanguage('en', 'include/phpmailer/language/'); 77 $this->PluginDir = 'include/phpmailer/'; 78 $this->Mailer = 'sendmail'; 79 // cn: i18n 80 $this->CharSet = $locale->getPrecedentPreference('default_email_charset'); 81 $this->Encoding = 'quoted-printable'; 82 $this->IsHTML(false); // default to plain-text email 83 $this->Hostname = $sugar_config['host_name']; 84 $this->WordWrap = 996; 85 // cn: gmail fix 86 $this->protocol = ($this->oe->mail_smtpssl == 1) ? "ssl://" : $this->protocol; 87 88 89 90 91 } 92 93 94 /** 95 * Prefills outbound details 96 */ 97 function setMailer() { 98 global $current_user; 99 100 require_once ("include/OutboundEmail/OutboundEmail.php"); 101 $oe = new OutboundEmail(); 102 $oe = $oe->getUserMailerSettings($current_user, $mailer_id, $ieId); 103 104 // ssl or tcp - keeping outside isSMTP b/c a default may inadvertantly set ssl:// 105 $this->protocol = ($oe->mail_smtpssl) ? "ssl://" : "tcp://"; 106 107 if($oe->mail_sendtype == "SMTP") { 108 $this->Mailer = "smtp"; 109 $this->Host = $oe->mail_smtpserver; 110 $this->Port = $oe->mail_smtpport; 111 if ($oe->mail_smtpssl == 1) { 112 $this->SMTPSecure = 'ssl'; 113 } // if 114 if ($oe->mail_smtpssl == 2) { 115 $this->SMTPSecure = 'tls'; 116 } // if 117 118 if($oe->mail_smtpauth_req) { 119 $this->SMTPAuth = TRUE; 120 $this->Username = $oe->mail_smtpuser; 121 $this->Password = $oe->mail_smtppass; 122 } 123 } else { 124 $this->Mailer = "sendmail"; 125 } 126 } 127 128 /** 129 * Prefills mailer for system 130 */ 131 function setMailerForSystem() { 132 require_once ("include/OutboundEmail/OutboundEmail.php"); 133 $oe = new OutboundEmail(); 134 $oe = $oe->getSystemMailerSettings(); 135 136 // ssl or tcp - keeping outside isSMTP b/c a default may inadvertantly set ssl:// 137 $this->protocol = ($oe->mail_smtpssl) ? "ssl://" : "tcp://"; 138 139 if($oe->mail_sendtype == "SMTP") { 140 $this->Mailer = "smtp"; 141 $this->Host = $oe->mail_smtpserver; 142 $this->Port = $oe->mail_smtpport; 143 if ($oe->mail_smtpssl == 1) { 144 $this->SMTPSecure = 'ssl'; 145 } // if 146 if ($oe->mail_smtpssl == 2) { 147 $this->SMTPSecure = 'tls'; 148 } // if 149 if($oe->mail_smtpauth_req) { 150 $this->SMTPAuth = TRUE; 151 $this->Username = $oe->mail_smtpuser; 152 $this->Password = $oe->mail_smtppass; 153 } 154 } else { 155 $this->Mailer = "sendmail"; 156 } 157 } 158 159 /** 160 * Attaches all fs, string, and binary attachments to the message. 161 * Returns an empty string on failure. 162 * @access private 163 * @return string 164 */ 165 function AttachAll() { 166 // Return text of body 167 $mime = array(); 168 169 // Add all attachments 170 for($i = 0; $i < count($this->attachment); $i++) { 171 // Check for string attachment 172 $bString = $this->attachment[$i][5]; 173 if ($bString) { 174 $string = $this->attachment[$i][0]; 175 } else { 176 $path = $this->attachment[$i][0]; 177 } 178 179 // cn: overriding parent class' method to perform encode on the following 180 $filename = $this->EncodeHeader(trim($this->attachment[$i][1])); 181 $name = $this->EncodeHeader(trim($this->attachment[$i][2])); 182 $encoding = $this->attachment[$i][3]; 183 $type = $this->attachment[$i][4]; 184 $disposition = $this->attachment[$i][6]; 185 $cid = $this->attachment[$i][7]; 186 187 $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); 188 $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE); 189 $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); 190 191 if($disposition == "inline") { 192 $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); 193 } 194 195 $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE.$this->LE); 196 197 // Encode as string attachment 198 if($bString) { 199 $mime[] = $this->EncodeString($string, $encoding); 200 if($this->IsError()) { return ""; } 201 $mime[] = $this->LE.$this->LE; 202 } else { 203 $mime[] = $this->EncodeFile($path, $encoding); 204 205 if($this->IsError()) { 206 return ""; 207 } 208 $mime[] = $this->LE.$this->LE; 209 } 210 } 211 $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); 212 213 return join("", $mime); 214 } 215 216 /** 217 * handles Charset translation for all visual parts of the email. 218 * @param string charset Default = '' 219 */ 220 function prepForOutbound() { 221 global $locale; 222 223 if($this->preppedForOutbound == false) { 224 //bug 28534. We should not set it to true to circumvent the following convertion as each email is independent. 225 //$this->preppedForOutbound = true; // flag so we don't redo this 226 $OBCharset = $locale->getPrecedentPreference('default_email_charset'); 227 228 // handle disclosure 229 if($this->disclosureEnabled) { 230 $this->Body .= "<br /> <br />{$this->disclosureText}"; 231 $this->AltBody .= "\r\r{$this->disclosureText}"; 232 } 233 234 // body text 235 $this->Body = from_html($locale->translateCharset(trim($this->Body), 'UTF-8', $OBCharset)); 236 $this->AltBody = from_html($locale->translateCharset(trim($this->AltBody), 'UTF-8', $OBCharset)); 237 $subjectUTF8 = from_html(trim($this->Subject)); 238 $subject = $locale->translateCharset($subjectUTF8, 'UTF-8', $OBCharset); 239 $this->Subject = $locale->translateCharset($subjectUTF8, 'UTF-8', $OBCharset); 240 241 // HTML email RFC compliance 242 if($this->ContentType == "text/html") { 243 if(strpos($this->Body, '<html') === false) { 244 $head=<<<eoq 245 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 246 <html xmlns="http://www.w3.org/1999/xhtml"> 247 <head> 248 <meta http-equiv="Content-Type" content="text/html; charset={$OBCharset}" /> 249 <title>{$subject}</title> 250 </head> 251 <body> 252 eoq; 253 $this->Body = $head.$this->Body."</body></html>"; 254 } 255 } 256 257 // Headers ///////////////////////////////// 258 // the below is done in PHPMailer::CreateHeader(); 259 //$this->Subject = $locale->translateCharsetMIME(trim($this->Subject), 'UTF-8', $locale->getPrecedentPreference('default_email_charset')); 260 $this->FromName = $locale->translateCharset(trim($this->FromName), 'UTF-8', $OBCharset); 261 /* 262 foreach($this->ReplyTo as $k => $v) { 263 $this->ReplyTo[$k][1] = $locale->translateCharset(trim($v[1]), 'UTF-8', $OBCharset); 264 } 265 // TO: fields 266 foreach($this->to as $k => $toArr) { 267 $this->to[$k][1] = $locale->translateCharset(trim($toArr[1]), 'UTF-8', $OBCharset); 268 } 269 // CC: fields 270 foreach($this->cc as $k => $ccAddr) { 271 $this->cc[$k][1] = $locale->translateCharset(trim($ccAddr[1]), 'UTF-8', $OBCharset); 272 } 273 // BCC: fields 274 foreach($this->bcc as $k => $bccAddr) { 275 $this->bcc[$k][1] = $locale->translateCharset(trim($bccAddr[1]), 'UTF-8', $OBCharset); 276 } 277 */ 278 279 } 280 } 281 282 /** 283 * @param notes array of note beans 284 */ 285 function handleAttachments($notes) { 286 global $sugar_config; 287 288 //replace references to cache/images with cid tag 289 $this->Body = str_replace($GLOBALS['sugar_config']['cache_dir'].'images/','cid:',$this->Body); 290 291 if (empty($notes)) { 292 return; 293 } 294 // cn: bug 4864 - reusing same SugarPHPMailer class, need to clear attachments 295 $this->ClearAttachments(); 296 require_once ('include/upload_file.php'); 297 298 $fileBasePath = "{$sugar_config['upload_dir']}"; 299 $filePatternSearch = "{$sugar_config['upload_dir']}"; 300 $filePatternSearch = str_replace("/", "\/", $filePatternSearch); 301 if(strpos($this->Body, "\"{$fileBasePath}")) { 302 $matches = array(); 303 preg_match_all("/{$filePatternSearch}.+?\"/i", $this->Body, $matches); 304 foreach($matches[0] as $match) { 305 $filename = str_replace($fileBasePath, '', $match); 306 $filename = urldecode(substr($filename, 0, -1)); 307 $cid = $filename; 308 $file_location = clean_path(getcwd()."/{$sugar_config['upload_dir']}{$filename}"); 309 $mime_type = "image/".strtolower(substr($filename, strrpos($filename, ".")+1, strlen($filename))); 310 if(file_exists($file_location)) { 311 $this->AddEmbeddedImage($file_location, $cid, $filename, 'base64', $mime_type); 312 } 313 } 314 //replace references to cache with cid tag 315 $this->Body = str_replace($fileBasePath,'cid:',$this->Body); 316 } 317 foreach($notes as $note) { 318 $mime_type = 'text/plain'; 319 $file_location = ''; 320 $filename = ''; 321 322 if($note->object_name == 'Note') { 323 if (! empty($note->file->temp_file_location) && is_file($note->file->temp_file_location)) { 324 $file_location = $note->file->temp_file_location; 325 $filename = $note->file->original_file_name; 326 $mime_type = $note->file->mime_type; 327 } else { 328 $file_location = rawurldecode(UploadFile::get_file_path($note->filename,$note->id)); 329 $filename = $note->id.$note->filename; 330 $mime_type = $note->file_mime_type; 331 } 332 } elseif($note->object_name == 'DocumentRevision') { // from Documents 333 $filename = $note->id.$note->filename; 334 $file_location = getcwd().'/'.$GLOBALS['sugar_config']['upload_dir'].$filename; 335 $mime_type = $note->file_mime_type; 336 } 337 338 $filename = substr($filename, 36, strlen($filename)); // strip GUID for PHPMailer class to name outbound file 339 if (!$note->embed_flag) { 340 $this->AddAttachment($file_location, $filename, 'base64', $mime_type); 341 } // else 342 } 343 } 344 345 /** 346 * overloads class.phpmailer's SetError() method so that we can log errors in sugarcrm.log 347 * 348 */ 349 function SetError($msg) { 350 $GLOBALS['log']->fatal("SugarPHPMailer encountered an error: {$msg}"); 351 parent::SetError($msg); 352 } 353 } // end class definition
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
|
|
|
|