smtps.class.php 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052
  1. <?php
  2. /*
  3. * Copyright (C) Walter Torres <walter@torres.ws> [with a *lot* of help!]
  4. * Copyright (C) 2005-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2006-2011 Regis Houssin
  6. * Copyright (C) 2016 Jonathan TISSEAU <jonathan.tisseau@86dev.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/core/class/smtps.class.php
  23. * \brief Class to construct and send SMTP compliant email, even to a secure
  24. * SMTP server, regardless of platform.
  25. * Goals:
  26. * - mime compliant
  27. * - multiple Reciptiants
  28. * - TO
  29. * - CC
  30. * - BCC
  31. * - multi-part message
  32. * - plain text
  33. * - HTML
  34. * - inline attachments
  35. * - attachments
  36. * - GPG access
  37. * This Class is based off of 'SMTP PHP MAIL' by Dirk Paehl, http://www.paehl.de
  38. */
  39. /**
  40. * Class to construct and send SMTP compliant email, even
  41. * to a secure SMTP server, regardless of platform.
  42. */
  43. class SMTPs
  44. {
  45. /**
  46. * Host Name or IP of SMTP Server to use
  47. */
  48. var $_smtpsHost = 'localhost';
  49. /**
  50. * SMTP Server Port definition. 25 is default value
  51. * This can be defined via a INI file or via a setter method
  52. */
  53. var $_smtpsPort = '25';
  54. /**
  55. * Secure SMTP Server access ID
  56. * This can be defined via a INI file or via a setter method
  57. */
  58. var $_smtpsID = null;
  59. /**
  60. * Secure SMTP Server access Password
  61. * This can be defined via a INI file or via a setter method
  62. */
  63. var $_smtpsPW = null;
  64. /**
  65. * Who sent the Message
  66. * This can be defined via a INI file or via a setter method
  67. */
  68. var $_msgFrom = null;
  69. /**
  70. * Where are replies and errors to be sent to
  71. * This can be defined via a INI file or via a setter method
  72. */
  73. var $_msgReplyTo = null;
  74. /**
  75. * Who will the Message be sent to; TO, CC, BCC
  76. * Multi-diminsional array containg addresses the message will
  77. * be sent TO, CC or BCC
  78. */
  79. var $_msgRecipients = null;
  80. /**
  81. * Message Subject
  82. */
  83. var $_msgSubject = null;
  84. /**
  85. * Message Content
  86. */
  87. var $_msgContent = null;
  88. /**
  89. * Custom X-Headers
  90. */
  91. var $_msgXheader = null;
  92. /**
  93. * Character set
  94. * Defaulted to 'iso-8859-1'
  95. */
  96. var $_smtpsCharSet = 'iso-8859-1';
  97. /**
  98. * Message Sensitivity
  99. * Defaults to ZERO - None
  100. */
  101. var $_msgSensitivity = 0;
  102. /**
  103. * Message Sensitivity
  104. */
  105. var $_arySensitivity = array ( false,
  106. 'Personal',
  107. 'Private',
  108. 'Company Confidential' );
  109. /**
  110. * Message Sensitivity
  111. * Defaults to 3 - Normal
  112. */
  113. var $_msgPriority = 3;
  114. /**
  115. * Message Priority
  116. */
  117. var $_aryPriority = array ( 'Bulk',
  118. 'Highest',
  119. 'High',
  120. 'Normal',
  121. 'Low',
  122. 'Lowest' );
  123. /**
  124. * Content-Transfer-Encoding
  125. * Defaulted to 0 - 7bit
  126. */
  127. var $_smtpsTransEncodeType = 0;
  128. /**
  129. * Content-Transfer-Encoding
  130. */
  131. var $_smtpsTransEncodeTypes = array( '7bit', // Simple 7-bit ASCII
  132. '8bit', // 8-bit coding with line termination characters
  133. 'base64', // 3 octets encoded into 4 sextets with offset
  134. 'binary', // Arbitrary binary stream
  135. 'mac-binhex40', // Macintosh binary to hex encoding
  136. 'quoted-printable', // Mostly 7-bit, with 8-bit characters encoded as "=HH"
  137. 'uuencode' ); // UUENCODE encoding
  138. /**
  139. * Content-Transfer-Encoding
  140. * Defaulted to '7bit'
  141. */
  142. var $_smtpsTransEncode = '7bit';
  143. /**
  144. * Boundary String for MIME seperation
  145. */
  146. var $_smtpsBoundary = null;
  147. /**
  148. * Related Boundary
  149. */
  150. var $_smtpsRelatedBoundary = null;
  151. /**
  152. * Alternative Boundary
  153. */
  154. var $_smtpsAlternativeBoundary = null;
  155. /**
  156. * Determines the method inwhich the message are to be sent.
  157. * - 'sockets' [0] - conect via network to SMTP server - default
  158. * - 'pipe [1] - use UNIX path to EXE
  159. * - 'phpmail [2] - use the PHP built-in mail function
  160. * NOTE: Only 'sockets' is implemented
  161. */
  162. var $_transportType = 0;
  163. /**
  164. * If '$_transportType' is set to '1', then this variable is used
  165. * to define the UNIX file system path to the sendmail execuable
  166. */
  167. var $_mailPath = '/usr/lib/sendmail';
  168. /**
  169. * Sets the SMTP server timeout in seconds.
  170. */
  171. var $_smtpTimeout = 10;
  172. /**
  173. * Determines whether to calculate message MD5 checksum.
  174. */
  175. var $_smtpMD5 = false;
  176. /**
  177. * Class error codes and messages
  178. */
  179. var $_smtpsErrors = null;
  180. /**
  181. * Defines log level
  182. * 0 - no logging
  183. * 1 - connectivity logging
  184. * 2 - message generation logging
  185. * 3 - detail logging
  186. */
  187. var $_log_level = 0;
  188. /**
  189. * Place Class in" debug" mode
  190. */
  191. var $_debug = false;
  192. // @CHANGE LDR
  193. var $log = '';
  194. var $_errorsTo = '';
  195. var $_deliveryReceipt = 0;
  196. var $_trackId = '';
  197. var $_moreInHeader = '';
  198. /**
  199. * Set delivery receipt
  200. *
  201. * @param int $_val Value
  202. * @return void
  203. */
  204. function setDeliveryReceipt($_val = 0)
  205. {
  206. $this->_deliveryReceipt = $_val;
  207. }
  208. /**
  209. * get delivery receipt
  210. *
  211. * @return int Delivery receipt
  212. */
  213. function getDeliveryReceipt()
  214. {
  215. return $this->_deliveryReceipt;
  216. }
  217. /**
  218. * Set trackid
  219. *
  220. * @param string $_val Value
  221. * @return void
  222. */
  223. function setTrackId($_val = '')
  224. {
  225. $this->_trackId = $_val;
  226. }
  227. /**
  228. * Set moreInHeader
  229. *
  230. * @param string $_val Value
  231. * @return void
  232. */
  233. function setMoreInHeader($_val = '')
  234. {
  235. $this->_moreinheader = $_val;
  236. }
  237. /**
  238. * get trackid
  239. *
  240. * @return string Track id
  241. */
  242. function getTrackId()
  243. {
  244. return $this->_trackId;
  245. }
  246. /**
  247. * get moreInHeader
  248. *
  249. * @return string moreInHeader
  250. */
  251. function getMoreInHeader()
  252. {
  253. return $this->_moreinheader;
  254. }
  255. /**
  256. * Set errors to
  257. *
  258. * @param string $_strErrorsTo Errors to
  259. * @return void
  260. */
  261. function setErrorsTo($_strErrorsTo)
  262. {
  263. if ( $_strErrorsTo )
  264. $this->_errorsTo = $this->_strip_email($_strErrorsTo);
  265. }
  266. /**
  267. * Get errors to
  268. *
  269. * @param boolean $_part Variant
  270. * @return string Errors to
  271. */
  272. function getErrorsTo($_part = true )
  273. {
  274. $_retValue = '';
  275. if ( $_part === true )
  276. $_retValue = $this->_errorsTo;
  277. else
  278. $_retValue = $this->_errorsTo[$_part];
  279. return $_retValue;
  280. }
  281. /**
  282. * Set debug
  283. *
  284. * @param boolean $_vDebug Value for debug
  285. * @return void
  286. */
  287. function setDebug($_vDebug = false )
  288. {
  289. $this->_debug = $_vDebug;
  290. }
  291. /**
  292. * build RECIPIENT List, all addresses who will recieve this message
  293. *
  294. * @return void
  295. */
  296. function buildRCPTlist()
  297. {
  298. // Pull TO list
  299. $_aryToList = $this->getTO();
  300. }
  301. /**
  302. * Attempt a connection to mail server
  303. *
  304. * @return mixed $_retVal Boolean indicating success or failure on connection
  305. */
  306. function _server_connect()
  307. {
  308. // Default return value
  309. $_retVal = true;
  310. // We have to make sure the HOST given is valid
  311. // This is done here because '@fsockopen' will not give me this
  312. // information if it failes to connect because it can't find the HOST
  313. $host=$this->getHost();
  314. $usetls = preg_match('@tls://@i',$host);
  315. $host=preg_replace('@tcp://@i','',$host); // Remove prefix
  316. $host=preg_replace('@ssl://@i','',$host); // Remove prefix
  317. $host=preg_replace('@tls://@i','',$host); // Remove prefix
  318. // @CHANGE LDR
  319. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  320. if ( (! is_ip($host)) && ((gethostbyname($host)) == $host))
  321. {
  322. $this->_setErr(99, $host . ' is either offline or is an invalid host name.');
  323. $_retVal = false;
  324. }
  325. else
  326. {
  327. //See if we can connect to the SMTP server
  328. if ($this->socket = @fsockopen(
  329. preg_replace('@tls://@i','',$this->getHost()), // Host to 'hit', IP or domain
  330. $this->getPort(), // which Port number to use
  331. $this->errno, // actual system level error
  332. $this->errstr, // and any text that goes with the error
  333. $this->_smtpTimeout
  334. )) // timeout for reading/writing data over the socket
  335. {
  336. // Fix from PHP SMTP class by 'Chris Ryan'
  337. // Sometimes the SMTP server takes a little longer to respond
  338. // so we will give it a longer timeout for the first read
  339. // Windows still does not have support for this timeout function
  340. if (function_exists('stream_set_timeout')) stream_set_timeout($this->socket, $this->_smtpTimeout, 0);
  341. // Check response from Server
  342. if ( $_retVal = $this->server_parse($this->socket, "220") )
  343. $_retVal = $this->socket;
  344. }
  345. // This connection attempt failed.
  346. else
  347. {
  348. // @CHANGE LDR
  349. if (empty($this->errstr)) $this->errstr='Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort();
  350. $this->_setErr($this->errno, $this->errstr);
  351. $_retVal = false;
  352. }
  353. }
  354. return $_retVal;
  355. }
  356. /**
  357. * Attempt mail server authentication for a secure connection
  358. *
  359. * @return boolean|null $_retVal Boolean indicating success or failure of authentication
  360. */
  361. function _server_authenticate()
  362. {
  363. global $conf;
  364. // Send the RFC2554 specified EHLO.
  365. // This improvment as provided by 'SirSir' to
  366. // accomodate both SMTP AND ESMTP capable servers
  367. $host=$this->getHost();
  368. $usetls = preg_match('@tls://@i',$host);
  369. $host=preg_replace('@tcp://@i','',$host); // Remove prefix
  370. $host=preg_replace('@ssl://@i','',$host); // Remove prefix
  371. $host=preg_replace('@tls://@i','',$host); // Remove prefix
  372. if ($usetls) $host='tls://'.$host;
  373. $hosth = $host;
  374. if (! empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO))
  375. {
  376. // If the from to is 'aaa <bbb@ccc.com>', we will keep 'ccc.com'
  377. $hosth = $this->getFrom('addr');
  378. $hosth = preg_replace('/^.*</', '', $hosth);
  379. $hosth = preg_replace('/>.*$/', '', $hosth);
  380. $hosth = preg_replace('/.*@/', '', $hosth);
  381. }
  382. if ( $_retVal = $this->socket_send_str('EHLO ' . $hosth, '250') )
  383. {
  384. if ($usetls)
  385. {
  386. /*
  387. The following dialog illustrates how a client and server can start a TLS STARTTLS session
  388. S: <waits for connection on TCP port 25>
  389. C: <opens connection>
  390. S: 220 mail.imc.org SMTP service ready
  391. C: EHLO mail.ietf.org
  392. S: 250-mail.imc.org offers a warm hug of welcome
  393. S: 250 STARTTLS
  394. C: STARTTLS
  395. S: 220 Go ahead
  396. C: <starts TLS negotiation>
  397. C & S: <negotiate a TLS session>
  398. C & S: <check result of negotiation>
  399. // Second pass EHLO
  400. C: EHLO client-domain.com
  401. S: 250-server-domain.com
  402. S: 250 AUTH LOGIN
  403. C: <continues by sending an SMTP command
  404. */
  405. if (!$_retVal = $this->socket_send_str('STARTTLS', 220))
  406. {
  407. $this->_setErr(131, 'STARTTLS connection is not supported.');
  408. return $_retVal;
  409. }
  410. // Before 5.6.7:
  411. // STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_SSLv2_CLIENT|STREAM_CRYPTO_METHOD_SSLv3_CLIENT
  412. // STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
  413. // PHP >= 5.6.7:
  414. // STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
  415. // STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT
  416. $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT;
  417. if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
  418. $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
  419. $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
  420. }
  421. if (!stream_socket_enable_crypto($this->socket, true, $crypto_method))
  422. {
  423. $this->_setErr(132, 'STARTTLS connection failed.');
  424. return $_retVal;
  425. }
  426. // Most server servers expect a 2nd pass of EHLO after TLS is established to get another time
  427. // the answer with list of supported AUTH methods. They may differs between non STARTTLS and with STARTTLS.
  428. if (!$_retVal = $this->socket_send_str('EHLO '.$host, '250'))
  429. {
  430. $this->_setErr(126, '"' . $host . '" does not support authenticated connections.');
  431. return $_retVal;
  432. }
  433. }
  434. // Send Authentication to Server
  435. // Check for errors along the way
  436. $this->socket_send_str('AUTH LOGIN', '334');
  437. // User name will not return any error, server will take anything we give it.
  438. $this->socket_send_str(base64_encode($this->_smtpsID), '334');
  439. // The error here just means the ID/password combo doesn't work.
  440. // There is not a method to determine which is the problem, ID or password
  441. if ( ! $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235') )
  442. $this->_setErr(130, 'Invalid Authentication Credentials.');
  443. }
  444. else
  445. {
  446. $this->_setErr(126, '"' . $host . '" does not support authenticated connections.');
  447. }
  448. return $_retVal;
  449. }
  450. /**
  451. * Now send the message
  452. *
  453. * @param boolean $_bolTestMsg whether to run this method in 'Test' mode.
  454. * @param boolean $_bolDebug whether to log all communication between this Class and the Mail Server.
  455. * @return boolean|null void
  456. * $_strMsg If this is run in 'Test' mode, the actual message structure will be returned
  457. */
  458. function sendMsg($_bolTestMsg = false, $_bolDebug = false)
  459. {
  460. global $conf;
  461. /**
  462. * Default return value
  463. */
  464. $_retVal = false;
  465. // Connect to Server
  466. if ( $this->socket = $this->_server_connect() )
  467. {
  468. // If a User ID *and* a password is given, assume Authentication is desired
  469. if( !empty($this->_smtpsID) && !empty($this->_smtpsPW) )
  470. {
  471. // Send the RFC2554 specified EHLO.
  472. $_retVal = $this->_server_authenticate();
  473. }
  474. // This is a "normal" SMTP Server "handshack"
  475. else
  476. {
  477. // Send the RFC821 specified HELO.
  478. $host=$this->getHost();
  479. $usetls = preg_match('@tls://@i',$host);
  480. $host=preg_replace('@tcp://@i','',$host); // Remove prefix
  481. $host=preg_replace('@ssl://@i','',$host); // Remove prefix
  482. $host=preg_replace('@tls://@i','',$host); // Remove prefix
  483. $hosth = $host;
  484. if (! empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO))
  485. {
  486. // If the from to is 'aaa <bbb@ccc.com>', we will keep 'ccc.com'
  487. $hosth = $this->getFrom('addr');
  488. $hosth = preg_replace('/^.*</', '', $hosth);
  489. $hosth = preg_replace('/>.*$/', '', $hosth);
  490. $hosth = preg_replace('/.*@/', '', $hosth);
  491. }
  492. $_retVal = $this->socket_send_str('HELO ' . $hosth, '250');
  493. }
  494. // Well, did we get to the server?
  495. if ( $_retVal )
  496. {
  497. // From this point onward most server response codes should be 250
  498. // Specify who the mail is from....
  499. // This has to be the raw email address, strip the "name" off
  500. $this->socket_send_str('MAIL FROM: ' . $this->getFrom('addr'), '250');
  501. // 'RCPT TO:' must be given a single address, so this has to loop
  502. // through the list of addresses, regardless of TO, CC or BCC
  503. // and send it out "single file"
  504. foreach ( $this->get_RCPT_list() as $_address )
  505. {
  506. /* Note:
  507. * BCC email addresses must be listed in the RCPT TO command list,
  508. * but the BCC header should not be printed under the DATA command.
  509. * http://stackoverflow.com/questions/2750211/sending-bcc-emails-using-a-smtp-server
  510. */
  511. /*
  512. * TODO
  513. * After each 'RCPT TO:' is sent, we need to make sure it was kosher,
  514. * if not, the whole message will fail
  515. * If any email address fails, we will need to RESET the connection,
  516. * mark the last address as "bad" and start the address loop over again.
  517. * If any address fails, the entire message fails.
  518. */
  519. $this->socket_send_str('RCPT TO: <' . $_address . '>', '250');
  520. }
  521. // Tell the server we are ready to start sending data
  522. // with any custom headers...
  523. // This is the last response code we look for until the end of the message.
  524. $this->socket_send_str('DATA', '354');
  525. // Now we are ready for the message...
  526. // Ok, all the ingredients are mixed in let's cook this puppy...
  527. $this->socket_send_str($this->getHeader().$this->getBodyContent() . "\r\n" . '.', '250');
  528. // Now tell the server we are done and close the socket...
  529. fputs($this->socket, 'QUIT');
  530. fclose($this->socket);
  531. }
  532. }
  533. return $_retVal;
  534. }
  535. // =============================================================
  536. // ** Setter & Getter methods
  537. // ** Basic System configuration
  538. /**
  539. * setConfig() is used to populate select class properties from either
  540. * a user defined INI file or the systems 'php.ini' file
  541. *
  542. * If a user defined INI is to be used, the files complete path is passed
  543. * as the method single parameter. The INI can define any class and/or
  544. * user properties. Only properties defined within this file will be setter
  545. * and/or orverwritten
  546. *
  547. * If the systems 'php.ini' file is to be used, the method is called without
  548. * parameters. In this case, only HOST, PORT and FROM properties will be set
  549. * as they are the only properties that are defined within the 'php.ini'.
  550. *
  551. * If secure SMTP is to be used, the user ID and Password can be defined with
  552. * the user INI file, but the properties are not defined with the systems
  553. * 'php.ini'file, they must be defined via their setter methods
  554. *
  555. * This method can be called twice, if desired. Once without a parameter to
  556. * load the properties as defined within the systems 'php.ini' file, and a
  557. * second time, with a path to a user INI file for other properties to be
  558. * defined.
  559. *
  560. * @param mixed $_strConfigPath path to config file or VOID
  561. * @return boolean
  562. */
  563. function setConfig($_strConfigPath = null)
  564. {
  565. /**
  566. * Returns constructed SELECT Object string or boolean upon failure
  567. * Default value is set at true
  568. */
  569. $_retVal = true;
  570. // if we have a path...
  571. if ( ! empty ($_strConfigPath) )
  572. {
  573. // If the path is not valid, this will NOT generate an error,
  574. // it will simply return false.
  575. if ( ! @include $_strConfigPath)
  576. {
  577. $this->_setErr(110, '"' . $_strConfigPath . '" is not a valid path.');
  578. $_retVal = false;
  579. }
  580. }
  581. // Read the Systems php.ini file
  582. else
  583. {
  584. // Set these properties ONLY if they are set in the php.ini file.
  585. // Otherwise the default values will be used.
  586. if ( $_host = ini_get('SMTPs') )
  587. $this->setHost($_host);
  588. if ( $_port = ini_get('smtp_port') )
  589. $this->setPort($_port);
  590. if ( $_from = ini_get('sendmail_from') )
  591. $this->setFrom($_from);
  592. }
  593. // Send back what we have
  594. return $_retVal;
  595. }
  596. /**
  597. * Determines the method inwhich the messages are to be sent.
  598. * - 'sockets' [0] - conect via network to SMTP server
  599. * - 'pipe [1] - use UNIX path to EXE
  600. * - 'phpmail [2] - use the PHP built-in mail function
  601. *
  602. * @param int $_type Interger value representing Mail Transport Type
  603. * @return void
  604. */
  605. function setTransportType($_type = 0)
  606. {
  607. if ( ( is_numeric($_type) ) &&
  608. ( ( $_type >= 0 ) && ( $_type <= 3 ) ) )
  609. $this->_transportType = $_type;
  610. }
  611. /**
  612. * Return the method inwhich the message is to be sent.
  613. * - 'sockets' [0] - conect via network to SMTP server
  614. * - 'pipe [1] - use UNIX path to EXE
  615. * - 'phpmail [2] - use the PHP built-in mail function
  616. *
  617. * @return int $_strHost Host Name or IP of the Mail Server to use
  618. */
  619. function getTransportType()
  620. {
  621. return $this->_transportType;
  622. }
  623. /**
  624. * Path to the sendmail execuable
  625. *
  626. * @param string $_path Path to the sendmail execuable
  627. * @return boolean
  628. *
  629. */
  630. function setMailPath($_path)
  631. {
  632. // This feature is not yet implemented
  633. return true;
  634. //if ( $_path ) $this->_mailPath = $_path;
  635. }
  636. /**
  637. * Defines the Host Name or IP of the Mail Server to use.
  638. * This is defaulted to 'localhost'
  639. * This is used only with 'socket' based mail transmission
  640. *
  641. * @param string $_strHost Host Name or IP of the Mail Server to use
  642. * @return void
  643. */
  644. function setHost($_strHost)
  645. {
  646. if ( $_strHost )
  647. $this->_smtpsHost = $_strHost;
  648. }
  649. /**
  650. * Retrieves the Host Name or IP of the Mail Server to use
  651. * This is used only with 'socket' based mail transmission
  652. *
  653. * @return string $_strHost Host Name or IP of the Mail Server to use
  654. */
  655. function getHost()
  656. {
  657. return $this->_smtpsHost;
  658. }
  659. /**
  660. * Defines the Port Number of the Mail Server to use
  661. * This is defaulted to '25'
  662. * This is used only with 'socket' based mail transmission
  663. *
  664. * @param int $_intPort Port Number of the Mail Server to use
  665. * @return void
  666. */
  667. function setPort($_intPort)
  668. {
  669. if ( ( is_numeric($_intPort) ) &&
  670. ( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) )
  671. $this->_smtpsPort = $_intPort;
  672. }
  673. /**
  674. * Retrieves the Port Number of the Mail Server to use
  675. * This is used only with 'socket' based mail transmission
  676. *
  677. * @return string Port Number of the Mail Server to use
  678. */
  679. function getPort()
  680. {
  681. return $this->_smtpsPort;
  682. }
  683. /**
  684. * User Name for authentication on Mail Server
  685. *
  686. * @param string $_strID User Name for authentication on Mail Server
  687. * @return void
  688. */
  689. function setID($_strID)
  690. {
  691. $this->_smtpsID = $_strID;
  692. }
  693. /**
  694. * Retrieves the User Name for authentication on Mail Server
  695. *
  696. * @return string User Name for authentication on Mail Server
  697. */
  698. function getID()
  699. {
  700. return $this->_smtpsID;
  701. }
  702. /**
  703. * User Password for authentication on Mail Server
  704. *
  705. * @param string $_strPW User Password for authentication on Mail Server
  706. * @return void
  707. */
  708. function setPW($_strPW)
  709. {
  710. $this->_smtpsPW = $_strPW;
  711. }
  712. /**
  713. * Retrieves the User Password for authentication on Mail Server
  714. *
  715. * @return string User Password for authentication on Mail Server
  716. */
  717. function getPW()
  718. {
  719. return $this->_smtpsPW;
  720. }
  721. /**
  722. * Character set used for current message
  723. * Character set is defaulted to 'iso-8859-1';
  724. *
  725. * @param string $_strCharSet Character set used for current message
  726. * @return void
  727. */
  728. function setCharSet($_strCharSet)
  729. {
  730. if ( $_strCharSet )
  731. $this->_smtpsCharSet = $_strCharSet;
  732. }
  733. /**
  734. * Retrieves the Character set used for current message
  735. *
  736. * @return string $_smtpsCharSet Character set used for current message
  737. */
  738. function getCharSet()
  739. {
  740. return $this->_smtpsCharSet;
  741. }
  742. /**
  743. * Content-Transfer-Encoding, Defaulted to '7bit'
  744. * This can be changed for 2byte characers sets
  745. * Known Encode Types
  746. * - 7bit Simple 7-bit ASCII
  747. * - 8bit 8-bit coding with line termination characters
  748. * - base64 3 octets encoded into 4 sextets with offset
  749. * - binary Arbitrary binary stream
  750. * - mac-binhex40 Macintosh binary to hex encoding
  751. * - quoted-printable Mostly 7-bit, with 8-bit characters encoded as "=HH"
  752. * - uuencode UUENCODE encoding
  753. *
  754. * @param string $_strTransEncode Content-Transfer-Encoding
  755. * @return void
  756. */
  757. function setTransEncode($_strTransEncode)
  758. {
  759. if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes))
  760. $this->_smtpsTransEncode = $_strTransEncode;
  761. }
  762. /**
  763. * Retrieves the Content-Transfer-Encoding
  764. *
  765. * @return string $_smtpsTransEncode Content-Transfer-Encoding
  766. */
  767. function getTransEncode()
  768. {
  769. return $this->_smtpsTransEncode;
  770. }
  771. /**
  772. * Content-Transfer-Encoding, Defaulted to '0' [ZERO]
  773. * This can be changed for 2byte characers sets
  774. * Known Encode Types
  775. * - [0] 7bit Simple 7-bit ASCII
  776. * - [1] 8bit 8-bit coding with line termination characters
  777. * - [2] base64 3 octets encoded into 4 sextets with offset
  778. * - [3] binary Arbitrary binary stream
  779. * - [4] mac-binhex40 Macintosh binary to hex encoding
  780. * - [5] quoted-printable Mostly 7-bit, with 8-bit characters encoded as "=HH"
  781. * - [6] uuencode UUENCODE encoding
  782. *
  783. * @param string $_strTransEncodeType Content-Transfer-Encoding
  784. * @return void
  785. *
  786. */
  787. function setTransEncodeType($_strTransEncodeType)
  788. {
  789. if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes))
  790. $this->_smtpsTransEncodeType = $_strTransEncodeType;
  791. }
  792. /**
  793. * Retrieves the Content-Transfer-Encoding
  794. *
  795. * @return string Content-Transfer-Encoding
  796. */
  797. function getTransEncodeType()
  798. {
  799. return $this->_smtpsTransEncodeTypes[$this->_smtpsTransEncodeType];
  800. }
  801. // ** Message Construction
  802. /**
  803. * FROM Address from which mail will be sent
  804. *
  805. * @param string $_strFrom Address from which mail will be sent
  806. * @return void
  807. */
  808. function setFrom($_strFrom)
  809. {
  810. if ( $_strFrom )
  811. $this->_msgFrom = $this->_strip_email($_strFrom);
  812. }
  813. /**
  814. * Retrieves the Address from which mail will be sent
  815. *
  816. * @param boolean $_part To "strip" 'Real name' from address
  817. * @return string Address from which mail will be sent
  818. */
  819. function getFrom($_part = true)
  820. {
  821. $_retValue = '';
  822. if ( $_part === true )
  823. $_retValue = $this->_msgFrom;
  824. else
  825. $_retValue = $this->_msgFrom[$_part];
  826. return $_retValue;
  827. }
  828. /**
  829. * Reply-To Address from which mail will be the reply-to
  830. *
  831. * @param string $_strReplyTo Address from which mail will be the reply-to
  832. * @return void
  833. */
  834. function setReplyTo($_strReplyTo)
  835. {
  836. if ( $_strReplyTo )
  837. $this->_msgReplyTo = $this->_strip_email($_strReplyTo);
  838. }
  839. /**
  840. * Retrieves the Address from which mail will be the reply-to
  841. *
  842. * @param boolean $_part To "strip" 'Real name' from address
  843. * @return string Address from which mail will be the reply-to
  844. */
  845. function getReplyTo($_part = true)
  846. {
  847. $_retValue = '';
  848. if ( $_part === true )
  849. $_retValue = $this->_msgReplyTo;
  850. else
  851. $_retValue = $this->_msgReplyTo[$_part];
  852. return $_retValue;
  853. }
  854. /**
  855. * Inserts given addresses into structured format.
  856. * This method takes a list of given addresses, via an array
  857. * or a COMMA delimted string, and inserts them into a highly
  858. * structured array. This array is designed to remove duplicate
  859. * addresses and to sort them by Domain.
  860. *
  861. * @param string $_type TO, CC, or BCC lists to add addrresses into
  862. * @param mixed $_addrList Array or COMMA delimited string of addresses
  863. * @return void
  864. *
  865. */
  866. function _buildAddrList($_type, $_addrList)
  867. {
  868. // Pull existing list
  869. $aryHost = $this->_msgRecipients;
  870. // Only run this if we have something
  871. if ( !empty ($_addrList ))
  872. {
  873. // $_addrList can be a STRING or an array
  874. if ( is_string($_addrList) )
  875. {
  876. // This could be a COMMA delimited string
  877. if ( strstr($_addrList, ',') )
  878. // "explode "list" into an array
  879. $_addrList = explode(',', $_addrList);
  880. // Stick it in an array
  881. else
  882. $_addrList = array($_addrList);
  883. }
  884. // take the array of addresses and split them further
  885. foreach ( $_addrList as $_strAddr )
  886. {
  887. // Strip off the end '>'
  888. $_strAddr = str_replace('>', '', $_strAddr);
  889. // Seperate "Real Name" from eMail address
  890. $_tmpaddr = null;
  891. $_tmpaddr = explode('<', $_strAddr);
  892. // We have a "Real Name" and eMail address
  893. if ( count($_tmpaddr) == 2 )
  894. {
  895. $_tmpHost = explode('@', $_tmpaddr[1]);
  896. $_tmpaddr[0] = trim($_tmpaddr[0], ' ">');
  897. $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = $_tmpaddr[0];
  898. }
  899. // We only have an eMail address
  900. else
  901. {
  902. // Strip off the beggining '<'
  903. $_strAddr = str_replace('<', '', $_strAddr);
  904. $_tmpHost = explode('@', $_strAddr);
  905. $_tmpHost[0] = trim($_tmpHost[0]);
  906. $_tmpHost[1] = trim($_tmpHost[1]);
  907. $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = '';
  908. }
  909. }
  910. }
  911. // replace list
  912. $this->_msgRecipients = $aryHost;
  913. }
  914. /**
  915. * Returns an array of the various parts of an email address
  916. * This assumes a well formed address:
  917. * - "Real name" <username@domain.tld>
  918. * - "Real Name" is optional
  919. * - if "Real Name" does not exist, the angle brackets are optional
  920. * This will split an email address into 4 or 5 parts.
  921. * - $_aryEmail[org] = orignal string
  922. * - $_aryEmail[real] = "real name" - if there is one
  923. * - $_aryEmail[addr] = address part "username@domain.tld"
  924. * - $_aryEmail[host] = "domain.tld"
  925. * - $_aryEmail[user] = "userName"
  926. *
  927. * @param string $_strAddr Email address
  928. * @return array An array of the various parts of an email address
  929. */
  930. function _strip_email($_strAddr)
  931. {
  932. // Keep the orginal
  933. $_aryEmail['org'] = $_strAddr;
  934. // Set entire string to Lower Case
  935. $_strAddr = strtolower($_strAddr);
  936. // Drop "stuff' off the end
  937. $_strAddr = trim($_strAddr, ' ">');
  938. // Seperate "Real Name" from eMail address, if we have one
  939. $_tmpAry = explode('<', $_strAddr);
  940. // Do we have a "Real name"
  941. if ( count($_tmpAry) == 2 )
  942. {
  943. // We may not really have a "Real Name"
  944. if ( $_tmpAry[0])
  945. $_aryEmail['real'] = trim($_tmpAry[0], ' ">');
  946. $_aryEmail['addr'] = $_tmpAry[1];
  947. }
  948. else
  949. $_aryEmail['addr'] = $_tmpAry[0];
  950. // Pull User Name and Host.tld apart
  951. list($_aryEmail['user'], $_aryEmail['host'] ) = explode('@', $_aryEmail['addr']);
  952. // Put the brackets back around the address
  953. $_aryEmail['addr'] = '<' . $_aryEmail['addr'] . '>';
  954. return $_aryEmail;
  955. }
  956. /**
  957. * Returns an array of bares addresses for use with 'RCPT TO:'
  958. * This is a "build as you go" method. Each time this method is called
  959. * the underlaying array is destroyed and reconstructed.
  960. *
  961. * @return array Returns an array of bares addresses
  962. */
  963. function get_RCPT_list()
  964. {
  965. /**
  966. * An array of bares addresses for use with 'RCPT TO:'
  967. */
  968. $_RCPT_list=array();
  969. // walk down Recipients array and pull just email addresses
  970. foreach ( $this->_msgRecipients as $_host => $_list )
  971. {
  972. foreach ( $_list as $_subList )
  973. {
  974. foreach ( $_subList as $_name => $_addr )
  975. {
  976. // build RCPT list
  977. $_RCPT_list[] = $_name . '@' . $_host;
  978. }
  979. }
  980. }
  981. return $_RCPT_list;
  982. }
  983. /**
  984. * Returns an array of addresses for a specific type; TO, CC or BCC
  985. *
  986. * @param string $_which Which collection of addresses to return ('to', 'cc', 'bcc')
  987. * @return string|false Array of emaill address
  988. */
  989. function get_email_list($_which = null)
  990. {
  991. // We need to know which address segment to pull
  992. if ( $_which )
  993. {
  994. // Make sure we have addresses to process
  995. if ( $this->_msgRecipients )
  996. {
  997. $_RCPT_list=array();
  998. // walk down Recipients array and pull just email addresses
  999. foreach ( $this->_msgRecipients as $_host => $_list )
  1000. {
  1001. if ( $this->_msgRecipients[$_host][$_which] )
  1002. {
  1003. foreach ( $this->_msgRecipients[$_host][$_which] as $_addr => $_realName )
  1004. {
  1005. if ( $_realName ) // @CHANGE LDR
  1006. {
  1007. $_realName = '"' . $_realName . '"';
  1008. $_RCPT_list[] = $_realName . ' <' . $_addr . '@' . $_host . '>';
  1009. }
  1010. else
  1011. {
  1012. $_RCPT_list[] = $_addr . '@' . $_host;
  1013. }
  1014. }
  1015. }
  1016. }
  1017. return implode(', ', $_RCPT_list);
  1018. }
  1019. else
  1020. {
  1021. $this->_setErr(101, 'No eMail Address for message to be sent to.');
  1022. return false;
  1023. }
  1024. }
  1025. else
  1026. {
  1027. $this->_setErr(102, 'eMail type not defined.');
  1028. return false;
  1029. }
  1030. }
  1031. /**
  1032. * TO Address[es] inwhich to send mail to
  1033. *
  1034. * @param string $_addrTo TO Address[es] inwhich to send mail to
  1035. * @return void
  1036. */
  1037. function setTO($_addrTo)
  1038. {
  1039. if ( $_addrTo )
  1040. $this->_buildAddrList('to', $_addrTo);
  1041. }
  1042. /**
  1043. * Retrieves the TO Address[es] inwhich to send mail to
  1044. *
  1045. * @return string TO Address[es] inwhich to send mail to
  1046. */
  1047. function getTo()
  1048. {
  1049. return $this->get_email_list('to');
  1050. }
  1051. /**
  1052. * CC Address[es] inwhich to send mail to
  1053. *
  1054. * @param string $_strCC CC Address[es] inwhich to send mail to
  1055. * @return void
  1056. */
  1057. function setCC($_strCC)
  1058. {
  1059. if ( $_strCC )
  1060. $this->_buildAddrList('cc', $_strCC);
  1061. }
  1062. /**
  1063. * Retrieves the CC Address[es] inwhich to send mail to
  1064. *
  1065. * @return string CC Address[es] inwhich to send mail to
  1066. */
  1067. function getCC()
  1068. {
  1069. return $this->get_email_list('cc');
  1070. }
  1071. /**
  1072. * BCC Address[es] inwhich to send mail to
  1073. *
  1074. * @param string $_strBCC Recipients BCC Address[es] inwhich to send mail to
  1075. * @return void
  1076. */
  1077. function setBCC($_strBCC)
  1078. {
  1079. if ( $_strBCC )
  1080. $this->_buildAddrList('bcc', $_strBCC);
  1081. }
  1082. /**
  1083. * Retrieves the BCC Address[es] inwhich to send mail to
  1084. *
  1085. * @return string BCC Address[es] inwhich to send mail to
  1086. */
  1087. function getBCC()
  1088. {
  1089. return $this->get_email_list('bcc');
  1090. }
  1091. /**
  1092. * Message Subject
  1093. *
  1094. * @param string $_strSubject Message Subject
  1095. * @return void
  1096. */
  1097. function setSubject($_strSubject = '')
  1098. {
  1099. if ( $_strSubject )
  1100. $this->_msgSubject = $_strSubject;
  1101. }
  1102. /**
  1103. * Retrieves the Message Subject
  1104. *
  1105. * @return string Message Subject
  1106. */
  1107. function getSubject()
  1108. {
  1109. return $this->_msgSubject;
  1110. }
  1111. /**
  1112. * Constructes and returns message header
  1113. *
  1114. * @return string Complete message header
  1115. */
  1116. function getHeader()
  1117. {
  1118. global $conf;
  1119. $_header = 'From: ' . $this->getFrom('org') . "\r\n"
  1120. . 'To: ' . $this->getTO() . "\r\n";
  1121. if ( $this->getCC() )
  1122. $_header .= 'Cc: ' . $this->getCC() . "\r\n";
  1123. /* Note:
  1124. * BCC email addresses must be listed in the RCPT TO command list,
  1125. * but the BCC header should not be printed under the DATA command.
  1126. * So it is included into the function sendMsg() but not here.
  1127. * http://stackoverflow.com/questions/2750211/sending-bcc-emails-using-a-smtp-server
  1128. */
  1129. /*
  1130. if ( $this->getBCC() )
  1131. $_header .= 'Bcc: ' . $this->getBCC() . "\r\n";
  1132. */
  1133. $host=$this->getHost();
  1134. $usetls = preg_match('@tls://@i',$host);
  1135. $host=preg_replace('@tcp://@i','',$host); // Remove prefix
  1136. $host=preg_replace('@ssl://@i','',$host); // Remove prefix
  1137. $host=preg_replace('@tls://@i','',$host); // Remove prefix
  1138. $host=dol_getprefix('email');
  1139. //NOTE: Message-ID should probably contain the username of the user who sent the msg
  1140. $_header .= 'Subject: ' . $this->getSubject() . "\r\n";
  1141. $_header .= 'Date: ' . date("r") . "\r\n";
  1142. $trackid = $this->getTrackId();
  1143. if ($trackid)
  1144. {
  1145. // References is kept in response and Message-ID is returned into In-Reply-To:
  1146. $_header .= 'Message-ID: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n";
  1147. $_header .= 'References: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n";
  1148. $_header .= 'X-Dolibarr-TRACKID: ' . $trackid . "\r\n";
  1149. }
  1150. else
  1151. {
  1152. $_header .= 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n";
  1153. }
  1154. if (! empty($_SERVER['REMOTE_ADDR'])) $_header .= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. "\r\n";
  1155. if ( $this->getMoreInHeader() )
  1156. $_header .= $this->getMoreInHeader(); // Value must include the "\r\n";
  1157. //$_header .=
  1158. // 'Read-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n"
  1159. // 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n";
  1160. if ( $this->getSensitivity() )
  1161. $_header .= 'Sensitivity: ' . $this->getSensitivity() . "\r\n";
  1162. if ( $this->_msgPriority != 3 )
  1163. $_header .= $this->getPriority();
  1164. // @CHANGE LDR
  1165. if ( $this->getDeliveryReceipt() )
  1166. $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n";
  1167. if ( $this->getErrorsTo() )
  1168. $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n";
  1169. if ( $this->getReplyTo() )
  1170. $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n";
  1171. $_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION .' (using SMTPs Mailer)' . "\r\n";
  1172. $_header .= 'X-Dolibarr-Option: '.($conf->global->MAIN_MAIL_USE_MULTI_PART?'MAIN_MAIL_USE_MULTI_PART':'No MAIN_MAIL_USE_MULTI_PART') . "\r\n";
  1173. $_header .= 'Mime-Version: 1.0' . "\r\n";
  1174. return $_header;
  1175. }
  1176. /**
  1177. * Message Content
  1178. *
  1179. * @param string $strContent Message Content
  1180. * @param string $strType Type
  1181. * @return void
  1182. */
  1183. function setBodyContent($strContent, $strType = 'plain')
  1184. {
  1185. //if ( $strContent )
  1186. //{
  1187. if ( $strType == 'html' )
  1188. $strMimeType = 'text/html';
  1189. else
  1190. $strMimeType = 'text/plain';
  1191. // Make RFC821 Compliant, replace bare linefeeds
  1192. $strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $strContent);
  1193. $strContentAltText = '';
  1194. if ($strType == 'html')
  1195. {
  1196. // Similar code to forge a text from html is also in CMailFile.class.php
  1197. $strContentAltText = preg_replace("/<br\s*[^>]*>/"," ", $strContent);
  1198. $strContentAltText = html_entity_decode(strip_tags($strContentAltText));
  1199. $strContentAltText = rtrim(wordwrap($strContentAltText, 75, "\r\n"));
  1200. }
  1201. // Make RFC2045 Compliant
  1202. //$strContent = rtrim(chunk_split($strContent)); // Function chunck_split seems ko if not used on a base64 content
  1203. $strContent = rtrim(wordwrap($strContent, 75, "\r\n")); // TODO Using this method creates unexpected line break on text/plain content.
  1204. $this->_msgContent[$strType] = array();
  1205. $this->_msgContent[$strType]['mimeType'] = $strMimeType;
  1206. $this->_msgContent[$strType]['data'] = $strContent;
  1207. $this->_msgContent[$strType]['dataText'] = $strContentAltText;
  1208. if ( $this->getMD5flag() )
  1209. $this->_msgContent[$strType]['md5'] = dol_hash($strContent, 3);
  1210. //}
  1211. }
  1212. /**
  1213. * Retrieves the Message Content
  1214. *
  1215. * @return string Message Content
  1216. */
  1217. function getBodyContent()
  1218. {
  1219. global $conf;
  1220. // Generate a new Boundary string
  1221. $this->_setBoundary();
  1222. // What type[s] of content do we have
  1223. $_types = array_keys($this->_msgContent);
  1224. // How many content types do we have
  1225. $keyCount = count($_types);
  1226. // If we have ZERO, we have a problem
  1227. if( $keyCount === 0 )
  1228. die ("Sorry, no content");
  1229. // If we have ONE, we can use the simple format
  1230. else if( $keyCount === 1 && empty($conf->global->MAIN_MAIL_USE_MULTI_PART))
  1231. {
  1232. $_msgData = $this->_msgContent;
  1233. $_msgData = $_msgData[$_types[0]];
  1234. $content = 'Content-Type: ' . $_msgData['mimeType'] . '; charset="' . $this->getCharSet() . '"' . "\r\n"
  1235. . 'Content-Transfer-Encoding: ' . $this->getTransEncodeType() . "\r\n"
  1236. . 'Content-Disposition: inline' . "\r\n"
  1237. . 'Content-Description: Message' . "\r\n";
  1238. if ( $this->getMD5flag() )
  1239. $content .= 'Content-MD5: ' . $_msgData['md5'] . "\r\n";
  1240. $content .= "\r\n"
  1241. . $_msgData['data'] . "\r\n";
  1242. }
  1243. // If we have more than ONE, we use the multi-part format
  1244. else if( $keyCount >= 1 || ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))
  1245. {
  1246. // Since this is an actual multi-part message
  1247. // We need to define a content message Boundary
  1248. // NOTE: This was 'multipart/alternative', but Windows based mail servers have issues with this.
  1249. //$content = 'Content-Type: multipart/related; boundary="' . $this->_getBoundary() . '"' . "\r\n";
  1250. $content = 'Content-Type: multipart/mixed; boundary="' . $this->_getBoundary('mixed') . '"' . "\r\n";
  1251. // . "\r\n"
  1252. // . 'This is a multi-part message in MIME format.' . "\r\n";
  1253. $content .= "Content-Transfer-Encoding: 8bit\r\n";
  1254. $content .= "\r\n";
  1255. $content .= "--" . $this->_getBoundary('mixed') . "\r\n";
  1256. if (key_exists('image', $this->_msgContent)) // If inline image found
  1257. {
  1258. $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n";
  1259. $content .= "\r\n";
  1260. $content .= "--" . $this->_getBoundary('alternative') . "\r\n";
  1261. }
  1262. // $this->_msgContent must be sorted with key 'text' or 'html' first then 'image' then 'attachment'
  1263. // Loop through message content array
  1264. foreach ($this->_msgContent as $type => $_content )
  1265. {
  1266. if ( $type == 'attachment' )
  1267. {
  1268. // loop through all attachments
  1269. foreach ( $_content as $_file => $_data )
  1270. {
  1271. $content .= "--" . $this->_getBoundary('mixed') . "\r\n"
  1272. . 'Content-Disposition: attachment; filename="' . $_data['fileName'] . '"' . "\r\n"
  1273. . 'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['fileName'] . '"' . "\r\n"
  1274. . 'Content-Transfer-Encoding: base64' . "\r\n"
  1275. . 'Content-Description: ' . $_data['fileName'] ."\r\n";
  1276. if ( $this->getMD5flag() )
  1277. $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n";
  1278. $content .= "\r\n" . $_data['data'] . "\r\n\r\n";
  1279. }
  1280. }
  1281. // @CHANGE LDR
  1282. else if ( $type == 'image' )
  1283. {
  1284. // loop through all images
  1285. foreach ( $_content as $_image => $_data )
  1286. {
  1287. $content .= "--" . $this->_getBoundary('related') . "\r\n"; // always related for an inline image
  1288. $content .= 'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['imageName'] . '"' . "\r\n"
  1289. . 'Content-Transfer-Encoding: base64' . "\r\n"
  1290. . 'Content-Disposition: inline; filename="' . $_data['imageName'] . '"' . "\r\n"
  1291. . 'Content-ID: <' . $_data['cid'] . '> ' . "\r\n";
  1292. if ( $this->getMD5flag() )
  1293. $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n";
  1294. $content .= "\r\n"
  1295. . $_data['data'] . "\r\n";
  1296. }
  1297. // always end related and end alternative after inline images
  1298. $content.= "--" . $this->_getBoundary('related') . "--" . "\r\n";
  1299. $content.= "\r\n" . "--" . $this->_getBoundary('alternative') . "--" . "\r\n";
  1300. $content.= "\r\n";
  1301. }
  1302. else
  1303. {
  1304. if (key_exists('image', $this->_msgContent))
  1305. {
  1306. $content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n";
  1307. $content.= "\r\n" . ($_content['dataText']?$_content['dataText']:strip_tags($_content['data'])) . "\r\n"; // Add plain text message
  1308. $content.= "--" . $this->_getBoundary('alternative') . "\r\n";
  1309. $content.= 'Content-Type: multipart/related; boundary="' . $this->_getBoundary('related') . '"' . "\r\n";
  1310. $content.= "\r\n";
  1311. $content.= "--" . $this->_getBoundary('related') . "\r\n";
  1312. }
  1313. if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part
  1314. {
  1315. $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n";
  1316. $content .= "\r\n";
  1317. $content .= "--" . $this->_getBoundary('alternative') . "\r\n";
  1318. $content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n";
  1319. $content.= "\r\n". $_content['dataText'] . "\r\n";
  1320. $content.= "--" . $this->_getBoundary('alternative') . "\r\n";
  1321. }
  1322. $content .= 'Content-Type: ' . $_content['mimeType'] . '; '
  1323. // . 'charset="' . $this->getCharSet() . '"';
  1324. . 'charset=' . $this->getCharSet() . '';
  1325. // $content .= ( $type == 'html') ? '; name="HTML Part"' : '';
  1326. $content .= "\r\n";
  1327. // $content .= 'Content-Transfer-Encoding: ';
  1328. // $content .= ($type == 'html') ? 'quoted-printable' : $this->getTransEncodeType();
  1329. // $content .= "\r\n"
  1330. // . 'Content-Disposition: inline' . "\r\n"
  1331. // . 'Content-Description: ' . $type . ' message' . "\r\n";
  1332. if ( $this->getMD5flag() )
  1333. $content .= 'Content-MD5: ' . $_content['md5'] . "\r\n";
  1334. $content .= "\r\n" . $_content['data'] . "\r\n";
  1335. if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part
  1336. {
  1337. $content.= "--" . $this->_getBoundary('alternative') . "--". "\r\n";
  1338. }
  1339. $content .= "\r\n";
  1340. }
  1341. }
  1342. // Close message boundries
  1343. // $content .= "\r\n--" . $this->_getBoundary() . '--' . "\r\n" ;
  1344. $content .= "--" . $this->_getBoundary('mixed') . '--' . "\r\n" ;
  1345. }
  1346. return $content;
  1347. }
  1348. /**
  1349. * File attachments are added to the content array as sub-arrays,
  1350. * allowing for multiple attachments for each outbound email
  1351. *
  1352. * @param string $strContent File data to attach to message
  1353. * @param string $strFileName File Name to give to attachment
  1354. * @param string $strMimeType File Mime Type of attachment
  1355. * @return void
  1356. */
  1357. function setAttachment($strContent, $strFileName = 'unknown', $strMimeType = 'unknown')
  1358. {
  1359. if ( $strContent )
  1360. {
  1361. $strContent = rtrim(chunk_split(base64_encode($strContent), 76, "\r\n")); // 76 max is defined into http://tools.ietf.org/html/rfc2047
  1362. $this->_msgContent['attachment'][$strFileName]['mimeType'] = $strMimeType;
  1363. $this->_msgContent['attachment'][$strFileName]['fileName'] = $strFileName;
  1364. $this->_msgContent['attachment'][$strFileName]['data'] = $strContent;
  1365. if ( $this->getMD5flag() )
  1366. $this->_msgContent['attachment'][$strFileName]['md5'] = dol_hash($strContent, 3);
  1367. }
  1368. }
  1369. // @CHANGE LDR
  1370. /**
  1371. * Image attachments are added to the content array as sub-arrays,
  1372. * allowing for multiple images for each outbound email
  1373. *
  1374. * @param string $strContent Image data to attach to message
  1375. * @param string $strImageName Image Name to give to attachment
  1376. * @param string $strMimeType Image Mime Type of attachment
  1377. * @param string $strImageCid CID
  1378. * @return void
  1379. */
  1380. function setImageInline($strContent, $strImageName = 'unknown', $strMimeType = 'unknown', $strImageCid = 'unknown')
  1381. {
  1382. if ($strContent)
  1383. {
  1384. $this->_msgContent['image'][$strImageName]['mimeType'] = $strMimeType;
  1385. $this->_msgContent['image'][$strImageName]['imageName'] = $strImageName;
  1386. $this->_msgContent['image'][$strImageName]['cid'] = $strImageCid;
  1387. $this->_msgContent['image'][$strImageName]['data'] = $strContent;
  1388. if ( $this->getMD5flag() )
  1389. $this->_msgContent['image'][$strImageName]['md5'] = dol_hash($strContent, 3);
  1390. }
  1391. }
  1392. // END @CHANGE LDR
  1393. /**
  1394. * Message Content Sensitivity
  1395. * Message Sensitivity values:
  1396. * - [0] None - default
  1397. * - [1] Personal
  1398. * - [2] Private
  1399. * - [3] Company Confidential
  1400. *
  1401. * @param integer $_value Message Sensitivity
  1402. * @return void
  1403. */
  1404. function setSensitivity($_value = 0)
  1405. {
  1406. if ( ( is_numeric($_value) ) &&
  1407. ( ( $_value >= 0 ) && ( $_value <= 3 ) ) )
  1408. $this->_msgSensitivity = $_value;
  1409. }
  1410. /**
  1411. * Returns Message Content Sensitivity string
  1412. * Message Sensitivity values:
  1413. * - [0] None - default
  1414. * - [1] Personal
  1415. * - [2] Private
  1416. * - [3] Company Confidential
  1417. *
  1418. * @return void
  1419. */
  1420. function getSensitivity()
  1421. {
  1422. return $this->_arySensitivity[$this->_msgSensitivity];
  1423. }
  1424. /**
  1425. * Message Content Priority
  1426. * Message Priority values:
  1427. * - [0] 'Bulk'
  1428. * - [1] 'Highest'
  1429. * - [2] 'High'
  1430. * - [3] 'Normal' - default
  1431. * - [4] 'Low'
  1432. * - [5] 'Lowest'
  1433. *
  1434. * @param integer $_value Message Priority
  1435. * @return void
  1436. */
  1437. function setPriority ( $_value = 3 )
  1438. {
  1439. if ( ( is_numeric($_value) ) &&
  1440. ( ( $_value >= 0 ) && ( $_value <= 5 ) ) )
  1441. $this->_msgPriority = $_value;
  1442. }
  1443. /**
  1444. * Message Content Priority
  1445. * Message Priority values:
  1446. * - [0] 'Bulk'
  1447. * - [1] 'Highest'
  1448. * - [2] 'High'
  1449. * - [3] 'Normal' - default
  1450. * - [4] 'Low'
  1451. * - [5] 'Lowest'
  1452. *
  1453. * @return string
  1454. */
  1455. function getPriority()
  1456. {
  1457. return 'Importance: ' . $this->_aryPriority[$this->_msgPriority] . "\r\n"
  1458. . 'Priority: ' . $this->_aryPriority[$this->_msgPriority] . "\r\n"
  1459. . 'X-Priority: ' . $this->_msgPriority . ' (' . $this->_aryPriority[$this->_msgPriority] . ')' . "\r\n";
  1460. }
  1461. /**
  1462. * Set flag which determines whether to calculate message MD5 checksum.
  1463. *
  1464. * @param string $_flag Message Priority
  1465. * @return void
  1466. */
  1467. function setMD5flag($_flag = false)
  1468. {
  1469. $this->_smtpMD5 = $_flag;
  1470. }
  1471. /**
  1472. * Gets flag which determines whether to calculate message MD5 checksum.
  1473. *
  1474. * @return boolean Message Priority
  1475. */
  1476. function getMD5flag()
  1477. {
  1478. return $this->_smtpMD5;
  1479. }
  1480. /**
  1481. * Message X-Header Content
  1482. * This is a simple "insert". Whatever is given will be placed
  1483. * "as is" into the Xheader array.
  1484. *
  1485. * @param string $strXdata Message X-Header Content
  1486. * @return void
  1487. */
  1488. function setXheader($strXdata)
  1489. {
  1490. if ( $strXdata )
  1491. $this->_msgXheader[] = $strXdata;
  1492. }
  1493. /**
  1494. * Retrieves the Message X-Header Content
  1495. *
  1496. * @return string[] $_msgContent Message X-Header Content
  1497. */
  1498. function getXheader()
  1499. {
  1500. return $this->_msgXheader;
  1501. }
  1502. /**
  1503. * Generates Random string for MIME message Boundary
  1504. *
  1505. * @return void
  1506. */
  1507. function _setBoundary()
  1508. {
  1509. $this->_smtpsBoundary = "multipart_x." . time() . ".x_boundary";
  1510. $this->_smtpsRelatedBoundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3);
  1511. $this->_smtpsAlternativeBoundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3);
  1512. }
  1513. /**
  1514. * Retrieves the MIME message Boundary
  1515. *
  1516. * @param string $type Type of boundary
  1517. * @return string $_smtpsBoundary MIME message Boundary
  1518. */
  1519. function _getBoundary($type='mixed')
  1520. {
  1521. if ($type == 'mixed') return $this->_smtpsBoundary;
  1522. else if ($type == 'related') return $this->_smtpsRelatedBoundary;
  1523. else if ($type == 'alternative') return $this->_smtpsAlternativeBoundary;
  1524. }
  1525. /**
  1526. * This function has been modified as provided by SirSir to allow multiline responses when
  1527. * using SMTP Extensions
  1528. *
  1529. * @param Handler $socket Socket handler
  1530. * @param string $response Response. Example: "550 5.7.1 https://support.google.com/a/answer/6140680#invalidcred j21sm814390wre.3"
  1531. * @return boolean True or false
  1532. */
  1533. function server_parse($socket, $response)
  1534. {
  1535. /**
  1536. * Returns constructed SELECT Object string or boolean upon failure
  1537. * Default value is set at true
  1538. */
  1539. $_retVal = true;
  1540. $server_response = '';
  1541. // avoid infinite loop
  1542. $limit=0;
  1543. while (substr($server_response,3,1) != ' ' && $limit<100)
  1544. {
  1545. if (! ($server_response = fgets($socket, 256)))
  1546. {
  1547. $this->_setErr(121, "Couldn't get mail server response codes");
  1548. $_retVal = false;
  1549. break;
  1550. }
  1551. $limit++;
  1552. }
  1553. if (! (substr($server_response, 0, 3) == $response))
  1554. {
  1555. $this->_setErr(120, "Ran into problems sending Mail.\r\nResponse: $server_response");
  1556. $_retVal = false;
  1557. }
  1558. return $_retVal;
  1559. }
  1560. /**
  1561. * Send str
  1562. *
  1563. * @param string $_strSend String to send
  1564. * @param string $_returnCode Return code
  1565. * @param string $CRLF CRLF
  1566. * @return boolean|null True or false
  1567. */
  1568. function socket_send_str( $_strSend, $_returnCode = null, $CRLF = "\r\n" )
  1569. {
  1570. if ($this->_debug) $this->log.=$_strSend; // @CHANGE LDR for log
  1571. fputs($this->socket, $_strSend . $CRLF);
  1572. if ($this->_debug) $this->log.=' ('.$_returnCode.')' . $CRLF;
  1573. if ( $_returnCode )
  1574. return $this->server_parse($this->socket, $_returnCode);
  1575. }
  1576. // =============================================================
  1577. // ** Error handling methods
  1578. /**
  1579. * Defines errors codes and messages for Class
  1580. *
  1581. * @param int $_errNum Error Code Number
  1582. * @param string $_errMsg Error Message
  1583. * @return void
  1584. */
  1585. function _setErr ( $_errNum, $_errMsg )
  1586. {
  1587. $this->_smtpsErrors[] = array( 'num' => $_errNum,
  1588. 'msg' => $_errMsg );
  1589. }
  1590. /**
  1591. * Returns errors codes and messages for Class
  1592. *
  1593. * @return string $_errMsg Error Message
  1594. */
  1595. function getErrors()
  1596. {
  1597. $_errMsg = array();
  1598. if (is_array($this->_smtpsErrors))
  1599. {
  1600. foreach ( $this->_smtpsErrors as $_err => $_info )
  1601. {
  1602. $_errMsg[] = 'Error [' . $_info['num'] .']: '. $_info['msg'];
  1603. }
  1604. }
  1605. return implode("\n", $_errMsg);
  1606. }
  1607. }
  1608. // =============================================================
  1609. // ** CSV Version Control Info
  1610. /**
  1611. * Revision 2011/09/12 07:49:59 eldy
  1612. * Doxygen
  1613. *
  1614. * Revision 2011/09/06 06:53:53 hregis
  1615. * Fix: use dol_hash instead md5 php function
  1616. *
  1617. * Revision 2011/09/03 00:14:27 eldy
  1618. * Doxygen
  1619. *
  1620. * Revision 2011/08/28 14:24:23 eldy
  1621. * Doxygen
  1622. *
  1623. * Revision 2011/07/12 22:19:02 eldy
  1624. * Fix: Attachment fails if content was empty
  1625. *
  1626. * Revision 2011/06/20 23:17:50 hregis
  1627. * Fix: use best structure of mail
  1628. *
  1629. * Revision 2010/04/13 20:58:37 eldy
  1630. * Fix: Can provide ip address on smtps. Better error reporting.
  1631. *
  1632. * Revision 2010/04/13 20:30:25 eldy
  1633. * Fix: Can provide ip address on smtps. Better error reporting.
  1634. *
  1635. * Revision 2010/01/12 13:02:07 hregis
  1636. * Fix: missing attach-files
  1637. *
  1638. * Revision 2009/11/01 14:16:30 eldy
  1639. * Fix: Sending mail with SMTPS was not working.
  1640. *
  1641. * Revision 2009/10/20 13:14:47 hregis
  1642. * Fix: function "split" is deprecated since php 5.3.0
  1643. *
  1644. * Revision 2009/05/13 19:10:07 eldy
  1645. * New: Can use inline images.Everything seems to work with thunderbird and webmail gmail. New to be tested on other mail browsers.
  1646. *
  1647. * Revision 2009/05/13 14:49:30 eldy
  1648. * Fix: Make code so much simpler and solve a lot of problem with new version.
  1649. *
  1650. * Revision 2009/02/09 00:04:35 eldy
  1651. * Added support for SMTPS protocol
  1652. *
  1653. * Revision 2008/04/16 23:11:45 eldy
  1654. * New: Add action "Test server connectivity"
  1655. *
  1656. * Revision 1.18 2007/01/12 22:17:08 ongardie
  1657. * - Added full_http_site_root() to utils-misc.php
  1658. * - Made SMTPs' getError() easier to use
  1659. * - Improved activity modified emails
  1660. *
  1661. * Revision 1.17 2006/04/05 03:15:40 ongardie
  1662. * -Fixed method name typo that resulted in a fatal error.
  1663. *
  1664. * Revision 1.16 2006/03/08 04:05:25 jswalter
  1665. * - '$_smtpsTransEncode' was removed and '$_smtpsTransEncodeType' is now used
  1666. * - '$_smtpsTransEncodeType' is defaulted to ZERO
  1667. * - corrected 'setCharSet()' internal vars
  1668. * - defined '$_mailPath'
  1669. * - added '$_smtpMD5' as a class property
  1670. * - added 'setMD5flag()' to set above property
  1671. * - added 'getMD5flag()' to retrieve above property
  1672. * - 'setAttachment()' will add an MD5 checksum to attachements if above property is set
  1673. * - 'setBodyContent()' will add an MD5 checksum to message parts if above property is set
  1674. * - 'getBodyContent()' will insert the MD5 checksum for messages and attachments if above property is set
  1675. * - removed leading dashes from message boundry
  1676. * - added propery "Close message boundry" tomessage block
  1677. * - corrected some comments in various places
  1678. * - removed some incorrect comments in others
  1679. *
  1680. * Revision 1.15 2006/02/21 02:00:07 vanmer
  1681. * - patch to add support for sending to exim mail server
  1682. * - thanks to Diego Ongaro at ETSZONE (diego@etszone.com)
  1683. *
  1684. * Revision 1.14 2005/08/29 16:22:10 jswalter
  1685. * - change 'multipart/alternative' to 'multipart/mixed', but Windows based mail servers have issues with this.
  1686. * Bug 594
  1687. *
  1688. * Revision 1.13 2005/08/21 01:57:30 vanmer
  1689. * - added initialization for array if no recipients exist
  1690. *
  1691. * Revision 1.12 2005/08/20 12:04:30 braverock
  1692. * - remove potentially binary characters from Message-ID
  1693. * - add getHost to get the hostname of the mailserver
  1694. * - add username to Message-ID header
  1695. *
  1696. * Revision 1.11 2005/08/20 11:49:48 braverock
  1697. * - fix typos in boundary
  1698. * - remove potentially illegal characters from boundary
  1699. *
  1700. * Revision 1.10 2005/08/19 20:39:32 jswalter
  1701. * - added _server_connect()' as a seperate method to handle server connectivity.
  1702. * - added '_server_authenticate()' as a seperate method to handle server authentication.
  1703. * - 'sendMsg()' now uses the new methods to handle server communication.
  1704. * - modified 'server_parse()' and 'socket_send_str()' to give error codes and messages.
  1705. *
  1706. * Revision 1.9 2005/08/19 15:40:18 jswalter
  1707. * - IMPORTANT: 'setAttachement()' is now spelled correctly: 'setAttachment()'
  1708. * - added additional comment to several methods
  1709. * - added '$_smtpsTransEncodeTypes' array to limit encode types
  1710. * - added parameters to 'sendMsg()' for future development around debugging and logging
  1711. * - added error code within 'setConfig()' if the given path is not found
  1712. * - 'setTransportType()' now has parameter validation
  1713. * [this still is not implemented]
  1714. * - 'setPort()' now does parameter validation
  1715. * - 'setTransEncode()' now has parameter validation against '$_smtpsTransEncodeTypes'
  1716. * - modified 'get_email_list()' to handle error handling
  1717. * - 'setSensitivity()' now has parameter validation
  1718. * - 'setPriority()' now has parameter validation
  1719. *
  1720. * Revision 1.8 2005/06/24 21:00:20 jswalter
  1721. * - corrected comments
  1722. * - corrected the defualt value for 'setPriority()'
  1723. * - modified 'setAttachement()' to process multiple attachments correctly
  1724. * - modified 'getBodyContent()' to handle multiple attachments
  1725. * Bug 310
  1726. *
  1727. * Revision 1.7 2005/05/19 21:12:34 braverock
  1728. * - replace chunk_split() with wordwrap() to fix funky wrapping of templates
  1729. *
  1730. * Revision 1.6 2005/04/25 04:55:06 jswalter
  1731. * - cloned from Master Version
  1732. *
  1733. * Revision 1.10 2005/04/25 04:54:10 walter
  1734. * - "fixed" 'getBodyContent()' to handle a "simple" text only message
  1735. *
  1736. * Revision 1.9 2005/04/25 03:52:01 walter
  1737. * - replace closing curly bracket. Removed it in last revision!
  1738. *
  1739. * Revision 1.8 2005/04/25 02:29:49 walter
  1740. * - added '$_transportType' and its getter/setter methods.
  1741. * for future use. NOT yet implemented.
  1742. * - in 'sendMsg()', added HOST validation check
  1743. * - added error check for initial Socket Connection
  1744. * - created new method 'socket_send_str()' to process socket
  1745. * communication in a unified means. Socket calls within
  1746. * 'sendMsg()' have been modified to use this new method.
  1747. * - expanded comments in 'setConfig()'
  1748. * - added "error" check on PHP ini file properties. If these
  1749. * properties not set within the INI file, the default values
  1750. * will be used.
  1751. * - modified 'get_RCPT_list()' to reset itself each time it is called
  1752. * - modified 'setBodyContent()' to store data in a sub-array for better
  1753. * parsing within the 'getBodyContent()' method
  1754. * - modified 'getBodyContent()' to process contents array better.
  1755. * Also modified to handle attachements.
  1756. * - added 'setAttachement()' so files and other data can be attached
  1757. * to messages
  1758. * - added '_setErr()' and 'getErrors()' as an attempt to begin an error
  1759. * handling process within this class
  1760. *
  1761. * Revision 1.7 2005/04/13 15:23:50 walter
  1762. * - made 'CC' a conditional insert
  1763. * - made 'BCC' a conditional insert
  1764. * - fixed 'Message-ID'
  1765. * - corrected 'getSensitivity()'
  1766. * - modified '$_aryPriority[]' to proper values
  1767. * - updated 'setConfig()' to handle external Ini or 'php.ini'
  1768. *
  1769. * Revision 1.6 2005/03/15 17:34:06 walter
  1770. * - corrected Message Sensitivity property and method comments
  1771. * - added array to Message Sensitivity
  1772. * - added getSensitivity() method to use new Sensitivity array
  1773. * - created seters and getter for Priority with new Prioity value array property
  1774. * - changed config file include from 'include_once'
  1775. * - modified getHeader() to ustilize new Message Sensitivity and Priorty properties
  1776. *
  1777. * Revision 1.5 2005/03/14 22:25:27 walter
  1778. * - added references
  1779. * - added Message sensitivity as a property with Getter/Setter methods
  1780. * - boundary is now a property with Getter/Setter methods
  1781. * - added 'builtRCPTlist()'
  1782. * - 'sendMsg()' now uses Object properties and methods to build message
  1783. * - 'setConfig()' to load external file
  1784. * - 'setForm()' will "strip" the email address out of "address" string
  1785. * - modifed 'getFrom()' to handle "striping" the email address
  1786. * - '_buildArrayList()' creates a multi-dimensional array of addresses
  1787. * by domain, TO, CC & BCC and then by User Name.
  1788. * - '_strip_email()' pulls email address out of "full Address" string'
  1789. * - 'get_RCPT_list()' pulls out "bare" emaill address form address array
  1790. * - 'getHeader()' builds message Header from Object properties
  1791. * - 'getBodyContent()' builds full messsage body, even multi-part
  1792. *
  1793. * Revision 1.4 2005/03/02 20:53:35 walter
  1794. * - core Setters & Getters defined
  1795. * - added additional Class Properties
  1796. *
  1797. * Revision 1.3 2005/03/02 18:51:51 walter
  1798. * - added base 'Class Properties'
  1799. *
  1800. * Revision 1.2 2005/03/01 19:37:52 walter
  1801. * - CVS logging tags
  1802. * - more comments
  1803. * - more "shell"
  1804. * - some constants
  1805. *
  1806. * Revision 1.1 2005/03/01 19:22:49 walter
  1807. * - initial commit
  1808. * - basic shell with some commets
  1809. *
  1810. */