smtp.mail.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <?php
  2. /**
  3. * @file
  4. * The code processing mail in the smtp module.
  5. *
  6. */
  7. /**
  8. * Modify the drupal mail system to use smtp when sending emails.
  9. * Include the option to choose between plain text or HTML
  10. */
  11. class SmtpMailSystem implements MailSystemInterface {
  12. protected $AllowHtml;
  13. /**
  14. * Concatenate and wrap the e-mail body for either
  15. * plain-text or HTML emails.
  16. *
  17. * @param $message
  18. * A message array, as described in hook_mail_alter().
  19. *
  20. * @return
  21. * The formatted $message.
  22. */
  23. public function format(array $message) {
  24. $this->AllowHtml = variable_get('smtp_allowhtml', 0);
  25. // Join the body array into one string.
  26. $message['body'] = implode("\n\n", $message['body']);
  27. if ($this->AllowHtml == 0) {
  28. // Convert any HTML to plain-text.
  29. $message['body'] = drupal_html_to_text($message['body']);
  30. // Wrap the mail body for sending.
  31. $message['body'] = drupal_wrap_mail($message['body']);
  32. }
  33. return $message;
  34. }
  35. /**
  36. * Send the e-mail message.
  37. *
  38. * @see drupal_mail()
  39. *
  40. * @param $message
  41. * A message array, as described in hook_mail_alter().
  42. * @return
  43. * TRUE if the mail was successfully accepted, otherwise FALSE.
  44. */
  45. public function mail(array $message) {
  46. $id = $message['id'];
  47. $to = $message['to'];
  48. $from = $message['from'];
  49. $body = $message['body'];
  50. $headers = $message['headers'];
  51. $subject = $message['subject'];
  52. // Create a new PHPMailer object - autoloaded from registry.
  53. $mailer = new PHPMailer();
  54. // Turn on debugging, if requested.
  55. if (variable_get('smtp_debugging', 0) == 1) {
  56. $mailer->SMTPDebug = TRUE;
  57. }
  58. // Set the from name.
  59. if (variable_get('smtp_fromname', '') != '') {
  60. $from_name = variable_get('smtp_fromname', '');
  61. }
  62. else {
  63. // If value is not defined in settings, use site_name.
  64. $from_name = variable_get('site_name', '');
  65. }
  66. //Hack to fix reply-to issue.
  67. $properfrom = variable_get('site_mail', '');
  68. if (!empty($properfrom)) {
  69. $headers['From'] = $properfrom;
  70. }
  71. if (!isset($headers['Reply-To']) || empty($headers['Reply-To'])) {
  72. if (strpos($from, '<')) {
  73. $reply = preg_replace('/>.*/', '', preg_replace('/.*</', '', $from));
  74. }
  75. else {
  76. $reply = $from;
  77. }
  78. $headers['Reply-To'] = $reply;
  79. }
  80. // Blank value will let the e-mail address appear.
  81. if ($from == NULL || $from == '') {
  82. // If from e-mail address is blank, use smtp_from config option.
  83. if (($from = variable_get('smtp_from', '')) == '') {
  84. // If smtp_from config option is blank, use site_email.
  85. if (($from = variable_get('site_mail', '')) == '') {
  86. drupal_set_message(t('There is no submitted from address.'), 'error');
  87. watchdog('smtp', 'There is no submitted from address.', array(), WATCHDOG_ERROR);
  88. return FALSE;
  89. }
  90. }
  91. }
  92. if (preg_match('/^"?.*"?\s*<.*>$/', $from)) {
  93. // . == Matches any single character except line break characters \r and \n.
  94. // * == Repeats the previous item zero or more times.
  95. $from_name = preg_replace('/"?([^("\t\n)]*)"?.*$/', '$1', $from); // It gives: Name
  96. $from = preg_replace("/(.*)\<(.*)\>/i", '$2', $from); // It gives: name@domain.tld
  97. }
  98. elseif (!valid_email_address($from)) {
  99. drupal_set_message(t('The submitted from address (@from) is not valid.', array('@from' => $from)), 'error');
  100. watchdog('smtp', 'The submitted from address (@from) is not valid.', array('@from' => $from), WATCHDOG_ERROR);
  101. return FALSE;
  102. }
  103. // Defines the From value to what we expect.
  104. $mailer->From = $from;
  105. $mailer->FromName = $from_name;
  106. $mailer->Sender = $from;
  107. // Create the list of 'To:' recipients.
  108. $torecipients = explode(',', $to);
  109. foreach ($torecipients as $torecipient) {
  110. if (strpos($torecipient, '<') !== FALSE) {
  111. $toparts = explode(' <', $torecipient);
  112. $toname = $toparts[0];
  113. $toaddr = rtrim($toparts[1], '>');
  114. }
  115. else {
  116. $toname = '';
  117. $toaddr = $torecipient;
  118. }
  119. $mailer->AddAddress($toaddr, $toname);
  120. }
  121. // Parse the headers of the message and set the PHPMailer object's settings
  122. // accordingly.
  123. foreach ($headers as $key => $value) {
  124. //watchdog('error', 'Key: ' . $key . ' Value: ' . $value);
  125. switch (drupal_strtolower($key)) {
  126. case 'from':
  127. if ($from == NULL or $from == '') {
  128. // If a from value was already given, then set based on header.
  129. // Should be the most common situation since drupal_mail moves the
  130. // from to headers.
  131. $from = $value;
  132. $mailer->From = $value;
  133. // then from can be out of sync with from_name !
  134. $mailer->FromName = '';
  135. $mailer->Sender = $value;
  136. }
  137. break;
  138. case 'content-type':
  139. // Parse several values on the Content-type header, storing them in an array like
  140. // key=value -> $vars['key']='value'
  141. $vars = explode(';', $value);
  142. foreach ($vars as $i => $var) {
  143. if ($cut = strpos($var, '=')) {
  144. $new_var = trim(drupal_strtolower(drupal_substr($var, $cut + 1)));
  145. $new_key = trim(drupal_substr($var, 0, $cut));
  146. unset($vars[$i]);
  147. $vars[$new_key] = $new_var;
  148. }
  149. }
  150. // Set the charset based on the provided value, otherwise set it to UTF-8 (which is Drupals internal default).
  151. $mailer->CharSet = isset($vars['charset']) ? $vars['charset'] : 'UTF-8';
  152. // If $vars is empty then set an empty value at index 0 to avoid a PHP warning in the next statement
  153. $vars[0] = isset($vars[0])?$vars[0]:'';
  154. switch ($vars[0]) {
  155. case 'text/plain':
  156. // The message includes only a plain text part.
  157. $mailer->IsHTML(FALSE);
  158. $content_type = 'text/plain';
  159. break;
  160. case 'text/html':
  161. // The message includes only an HTML part.
  162. $mailer->IsHTML(TRUE);
  163. $content_type = 'text/html';
  164. break;
  165. case 'multipart/related':
  166. // Get the boundary ID from the Content-Type header.
  167. $boundary = $this->_get_substring($value, 'boundary', '"', '"');
  168. // The message includes an HTML part w/inline attachments.
  169. $mailer->ContentType = $content_type = 'multipart/related; boundary="' . $boundary . '"';
  170. break;
  171. case 'multipart/alternative':
  172. // The message includes both a plain text and an HTML part.
  173. $mailer->ContentType = $content_type = 'multipart/alternative';
  174. // Get the boundary ID from the Content-Type header.
  175. $boundary = $this->_get_substring($value, 'boundary', '"', '"');
  176. break;
  177. case 'multipart/mixed':
  178. // The message includes one or more attachments.
  179. $mailer->ContentType = $content_type = 'multipart/mixed';
  180. // Get the boundary ID from the Content-Type header.
  181. $boundary = $this->_get_substring($value, 'boundary', '"', '"');
  182. break;
  183. default:
  184. // Everything else is unsuppored by PHPMailer.
  185. drupal_set_message(t('The %header of your message is not supported by PHPMailer and will be sent as text/plain instead.', array('%header' => "Content-Type: $value")), 'error');
  186. watchdog('smtp', 'The %header of your message is not supported by PHPMailer and will be sent as text/plain instead.', array('%header' => "Content-Type: $value"), WATCHDOG_ERROR);
  187. // Force the Content-Type to be text/plain.
  188. $mailer->IsHTML(FALSE);
  189. $content_type = 'text/plain';
  190. }
  191. break;
  192. case 'reply-to':
  193. // Only add a "reply-to" if it's not the same as "return-path".
  194. if ($value != $headers['Return-Path']) {
  195. if (strpos($value, '<') !== FALSE) {
  196. $replyToParts = explode('<', $value);
  197. $replyToName = trim($replyToParts[0]);
  198. $replyToName = trim($replyToName, '"');
  199. $replyToAddr = rtrim($replyToParts[1], '>');
  200. $mailer->AddReplyTo($replyToAddr, $replyToName);
  201. }
  202. else {
  203. $mailer->AddReplyTo($value);
  204. }
  205. }
  206. break;
  207. case 'content-transfer-encoding':
  208. $mailer->Encoding = $value;
  209. break;
  210. case 'return-path':
  211. if (strpos($value, '<') !== FALSE) {
  212. $returnPathParts = explode('<', $value);
  213. $returnPathAddr = rtrim($returnPathParts[1], '>');
  214. $mailer->Sender = $returnPathAddr;
  215. }
  216. else {
  217. $mailer->Sender = $value;
  218. }
  219. break;
  220. case 'mime-version':
  221. case 'x-mailer':
  222. // Let PHPMailer specify these.
  223. break;
  224. case 'errors-to':
  225. $mailer->AddCustomHeader('Errors-To: ' . $value);
  226. break;
  227. case 'cc':
  228. $ccrecipients = explode(',', $value);
  229. foreach ($ccrecipients as $ccrecipient) {
  230. if (strpos($ccrecipient, '<') !== FALSE) {
  231. $ccparts = explode(' <', $ccrecipient);
  232. $ccname = $ccparts[0];
  233. $ccaddr = rtrim($ccparts[1], '>');
  234. }
  235. else {
  236. $ccname = '';
  237. $ccaddr = $ccrecipient;
  238. }
  239. $mailer->AddCC($ccaddr, $ccname);
  240. }
  241. break;
  242. case 'bcc':
  243. $bccrecipients = explode(',', $value);
  244. foreach ($bccrecipients as $bccrecipient) {
  245. if (strpos($bccrecipient, '<') !== FALSE) {
  246. $bccparts = explode(' <', $bccrecipient);
  247. $bccname = $bccparts[0];
  248. $bccaddr = rtrim($bccparts[1], '>');
  249. }
  250. else {
  251. $bccname = '';
  252. $bccaddr = $bccrecipient;
  253. }
  254. $mailer->AddBCC($bccaddr, $bccname);
  255. }
  256. break;
  257. case 'message-id':
  258. $mailer->MessageID = $value;
  259. break;
  260. default:
  261. // The header key is not special - add it as is.
  262. $mailer->AddCustomHeader($key . ': ' . $value);
  263. }
  264. }
  265. /**
  266. * TODO
  267. * Need to figure out the following.
  268. *
  269. * Add one last header item, but not if it has already been added.
  270. * $errors_to = FALSE;
  271. * foreach ($mailer->CustomHeader as $custom_header) {
  272. * if ($custom_header[0] = '') {
  273. * $errors_to = TRUE;
  274. * }
  275. * }
  276. * if ($errors_to) {
  277. * $mailer->AddCustomHeader('Errors-To: '. $from);
  278. * }
  279. */
  280. // Add the message's subject.
  281. $mailer->Subject = $subject;
  282. // Processes the message's body.
  283. switch ($content_type) {
  284. case 'multipart/related':
  285. $mailer->Body = $body;
  286. // TODO: Figure out if there is anything more to handling this type.
  287. break;
  288. case 'multipart/alternative':
  289. // Split the body based on the boundary ID.
  290. $body_parts = $this->_boundary_split($body, $boundary);
  291. foreach ($body_parts as $body_part) {
  292. // If plain/text within the body part, add it to $mailer->AltBody.
  293. if (strpos($body_part, 'text/plain')) {
  294. // Clean up the text.
  295. $body_part = trim($this->_remove_headers(trim($body_part)));
  296. // Include it as part of the mail object.
  297. $mailer->AltBody = $body_part;
  298. }
  299. // If plain/html within the body part, add it to $mailer->Body.
  300. elseif (strpos($body_part, 'text/html')) {
  301. // Clean up the text.
  302. $body_part = trim($this->_remove_headers(trim($body_part)));
  303. // Include it as part of the mail object.
  304. $mailer->Body = $body_part;
  305. }
  306. }
  307. break;
  308. case 'multipart/mixed':
  309. // Split the body based on the boundary ID.
  310. $body_parts = $this->_boundary_split($body, $boundary);
  311. // Determine if there is an HTML part for when adding the plain text part.
  312. $text_plain = FALSE;
  313. $text_html = FALSE;
  314. foreach ($body_parts as $body_part) {
  315. if (strpos($body_part, 'text/plain')) {
  316. $text_plain = TRUE;
  317. }
  318. if (strpos($body_part, 'text/html')) {
  319. $text_html = TRUE;
  320. }
  321. }
  322. foreach ($body_parts as $body_part) {
  323. // If test/plain within the body part, add it to either
  324. // $mailer->AltBody or $mailer->Body, depending on whether there is
  325. // also a text/html part ot not.
  326. if (strpos($body_part, 'multipart/alternative')) {
  327. // Get boundary ID from the Content-Type header.
  328. $boundary2 = $this->_get_substring($body_part, 'boundary', '"', '"');
  329. // Clean up the text.
  330. $body_part = trim($this->_remove_headers(trim($body_part)));
  331. // Split the body based on the boundary ID.
  332. $body_parts2 = $this->_boundary_split($body_part, $boundary2);
  333. foreach ($body_parts2 as $body_part2) {
  334. // If plain/text within the body part, add it to $mailer->AltBody.
  335. if (strpos($body_part2, 'text/plain')) {
  336. // Clean up the text.
  337. $body_part2 = trim($this->_remove_headers(trim($body_part2)));
  338. // Include it as part of the mail object.
  339. $mailer->AltBody = $body_part2;
  340. $mailer->ContentType = 'multipart/mixed';
  341. }
  342. // If plain/html within the body part, add it to $mailer->Body.
  343. elseif (strpos($body_part2, 'text/html')) {
  344. // Get the encoding.
  345. $body_part2_encoding = $this->_get_substring($body_part2, 'Content-Transfer-Encoding', ':', "\n");
  346. // Clean up the text.
  347. $body_part2 = trim($this->_remove_headers(trim($body_part2)));
  348. // Check whether the encoding is base64, and if so, decode it.
  349. if (drupal_strtolower($body_part2_encoding) == 'base64') {
  350. // Include it as part of the mail object.
  351. $mailer->Body = base64_decode($body_part2);
  352. // Ensure the whole message is recoded in the base64 format.
  353. $mailer->Encoding = 'base64';
  354. }
  355. else {
  356. // Include it as part of the mail object.
  357. $mailer->Body = $body_part2;
  358. }
  359. $mailer->ContentType = 'multipart/mixed';
  360. }
  361. }
  362. }
  363. // If text/plain within the body part, add it to $mailer->Body.
  364. elseif (strpos($body_part, 'text/plain')) {
  365. // Clean up the text.
  366. $body_part = trim($this->_remove_headers(trim($body_part)));
  367. if ($text_html) {
  368. $mailer->AltBody = $body_part;
  369. $mailer->IsHTML(TRUE);
  370. $mailer->ContentType = 'multipart/mixed';
  371. }
  372. else {
  373. $mailer->Body = $body_part;
  374. $mailer->IsHTML(FALSE);
  375. $mailer->ContentType = 'multipart/mixed';
  376. }
  377. }
  378. // If text/html within the body part, add it to $mailer->Body.
  379. elseif (strpos($body_part, 'text/html')) {
  380. // Clean up the text.
  381. $body_part = trim($this->_remove_headers(trim($body_part)));
  382. // Include it as part of the mail object.
  383. $mailer->Body = $body_part;
  384. $mailer->IsHTML(TRUE);
  385. $mailer->ContentType = 'multipart/mixed';
  386. }
  387. // Add the attachment.
  388. elseif (strpos($body_part, 'Content-Disposition: attachment;') && !isset($message['params']['attachments'])) {
  389. $file_path = $this->_get_substring($body_part, 'filename=', '"', '"');
  390. $file_name = $this->_get_substring($body_part, ' name=', '"', '"');
  391. $file_encoding = $this->_get_substring($body_part, 'Content-Transfer-Encoding', ' ', "\n");
  392. $file_type = $this->_get_substring($body_part, 'Content-Type', ' ', ';');
  393. if (file_exists($file_path)) {
  394. if (!$mailer->AddAttachment($file_path, $file_name, $file_encoding, $file_type)) {
  395. drupal_set_message(t('Attahment could not be found or accessed.'));
  396. }
  397. }
  398. else {
  399. // Clean up the text.
  400. $body_part = trim($this->_remove_headers(trim($body_part)));
  401. if (drupal_strtolower($file_encoding) == 'base64') {
  402. $attachment = base64_decode($body_part);
  403. }
  404. elseif (drupal_strtolower($file_encoding) == 'quoted-printable') {
  405. $attachment = quoted_printable_decode($body_part);
  406. }
  407. else {
  408. $attachment = $body_part;
  409. }
  410. $attachment_new_filename = drupal_tempnam('temporary://', 'smtp');
  411. $file_path = file_save_data($attachment, $attachment_new_filename, FILE_EXISTS_REPLACE);
  412. $real_path = drupal_realpath($file_path->uri);
  413. if (!$mailer->AddAttachment($real_path, $file_name)) {
  414. drupal_set_message(t('Attachment could not be found or accessed.'));
  415. }
  416. }
  417. }
  418. }
  419. break;
  420. default:
  421. $mailer->Body = $body;
  422. break;
  423. }
  424. // Process mimemail attachments, which are prepared in mimemail_mail().
  425. if (isset($message['params']['attachments'])) {
  426. foreach ($message['params']['attachments'] as $attachment) {
  427. if (isset($attachment['filecontent'])) {
  428. $mailer->AddStringAttachment($attachment['filecontent'], $attachment['filename'], 'base64', $attachment['filemime']);
  429. }
  430. if (isset($attachment['filepath'])) {
  431. $filename = isset($attachment['filename']) ? $attachment['filename'] : basename($attachment['filepath']);
  432. $filemime = isset($attachment['filemime']) ? $attachment['filemime'] : file_get_mimetype($attachment['filepath']);
  433. $mailer->AddAttachment($attachment['filepath'], $filename, 'base64', $filemime);
  434. }
  435. }
  436. }
  437. // Set the authentication settings.
  438. $username = variable_get('smtp_username', '');
  439. $password = variable_get('smtp_password', '');
  440. // If username and password are given, use SMTP authentication.
  441. if ($username != '' && $password != '') {
  442. $mailer->SMTPAuth = TRUE;
  443. $mailer->Username = $username;
  444. $mailer->Password = $password;
  445. }
  446. // Set the protocol prefix for the smtp host.
  447. switch (variable_get('smtp_protocol', 'standard')) {
  448. case 'ssl':
  449. $mailer->SMTPSecure = 'ssl';
  450. break;
  451. case 'tls':
  452. $mailer->SMTPSecure = 'tls';
  453. break;
  454. default:
  455. $mailer->SMTPSecure = '';
  456. }
  457. // Set other connection settings.
  458. $mailer->Host = variable_get('smtp_host', '') . ';' . variable_get('smtp_hostbackup', '');
  459. $mailer->Port = variable_get('smtp_port', '25');
  460. $mailer->Mailer = 'smtp';
  461. $mailerArr = array(
  462. 'mailer' => $mailer,
  463. 'to' => $to,
  464. 'from' => $from,
  465. );
  466. if (variable_get('smtp_queue', FALSE)) {
  467. watchdog('smtp', 'Queue sending mail to: @to', array('@to' => $to));
  468. smtp_send_queue($mailerArr);
  469. }
  470. else {
  471. return _smtp_mailer_send($mailerArr);
  472. }
  473. return TRUE;
  474. }
  475. /**
  476. * Splits the input into parts based on the given boundary.
  477. *
  478. * Swiped from Mail::MimeDecode, with modifications based on Drupal's coding
  479. * standards and this bug report: http://pear.php.net/bugs/bug.php?id=6495
  480. *
  481. * @param input
  482. * A string containing the body text to parse.
  483. * @param boundary
  484. * A string with the boundary string to parse on.
  485. * @return
  486. * An array containing the resulting mime parts
  487. */
  488. protected function _boundary_split($input, $boundary) {
  489. $parts = array();
  490. $bs_possible = drupal_substr($boundary, 2, -2);
  491. $bs_check = '\"' . $bs_possible . '\"';
  492. if ($boundary == $bs_check) {
  493. $boundary = $bs_possible;
  494. }
  495. $tmp = explode('--' . $boundary, $input);
  496. for ($i = 1; $i < count($tmp); $i++) {
  497. if (trim($tmp[$i])) {
  498. $parts[] = $tmp[$i];
  499. }
  500. }
  501. return $parts;
  502. } // End of _smtp_boundary_split().
  503. /**
  504. * Strips the headers from the body part.
  505. *
  506. * @param input
  507. * A string containing the body part to strip.
  508. * @return
  509. * A string with the stripped body part.
  510. */
  511. protected function _remove_headers($input) {
  512. $part_array = explode("\n", $input);
  513. // will strip these headers according to RFC2045
  514. $headers_to_strip = array( 'Content-Type', 'Content-Transfer-Encoding', 'Content-ID', 'Content-Disposition');
  515. $pattern = '/^(' . implode('|', $headers_to_strip) . '):/';
  516. while (count($part_array) > 0) {
  517. // ignore trailing spaces/newlines
  518. $line = rtrim($part_array[0]);
  519. // if the line starts with a known header string
  520. if (preg_match($pattern, $line)) {
  521. $line = rtrim(array_shift($part_array));
  522. // remove line containing matched header.
  523. // if line ends in a ';' and the next line starts with four spaces, it's a continuation
  524. // of the header split onto the next line. Continue removing lines while we have this condition.
  525. while (substr($line, -1) == ';' && count($part_array) > 0 && substr($part_array[0], 0, 4) == ' ') {
  526. $line = rtrim(array_shift($part_array));
  527. }
  528. }
  529. else {
  530. // no match header, must be past headers; stop searching.
  531. break;
  532. }
  533. }
  534. $output = implode("\n", $part_array);
  535. return $output;
  536. } // End of _smtp_remove_headers().
  537. /**
  538. * Returns a string that is contained within another string.
  539. *
  540. * Returns the string from within $source that is some where after $target
  541. * and is between $beginning_character and $ending_character.
  542. *
  543. * @param $source
  544. * A string containing the text to look through.
  545. * @param $target
  546. * A string containing the text in $source to start looking from.
  547. * @param $beginning_character
  548. * A string containing the character just before the sought after text.
  549. * @param $ending_character
  550. * A string containing the character just after the sought after text.
  551. * @return
  552. * A string with the text found between the $beginning_character and the
  553. * $ending_character.
  554. */
  555. protected function _get_substring($source, $target, $beginning_character, $ending_character) {
  556. $search_start = strpos($source, $target) + 1;
  557. $first_character = strpos($source, $beginning_character, $search_start) + 1;
  558. $second_character = strpos($source, $ending_character, $first_character) + 1;
  559. $substring = drupal_substr($source, $first_character, $second_character - $first_character);
  560. $string_length = drupal_strlen($substring) - 1;
  561. if ($substring[$string_length] == $ending_character) {
  562. $substring = drupal_substr($substring, 0, $string_length);
  563. }
  564. return $substring;
  565. } // End of _smtp_get_substring().
  566. }