18 include (
'Mail/mime.php');
19 include (
'Net/SMTP.php');
33 $rcpt = array_merge(explode(
',',
$to) , explode(
',',
$cc) , explode(
',',
$bcc));
35 $host =
getParam(
'SMTP_HOST',
'localhost');
40 if (is_a($mimemail,
'Mail_Mime')) {
41 $mimemail->setFrom(
$from);
42 if (
$cc !=
'') $mimemail->addCc(
$cc);
47 if (!($smtp =
new Net_SMTP($host,
$port))) {
48 die(
"Unable to instantiate Net_SMTP object\n");
50 $smtp->setDebug(
false);
52 if (PEAR::isError($e = $smtp->connect())) {
53 return (
"smtp connect:" . $e->getMessage());
57 if (PEAR::isError($e = $smtp->auth($login,
$password))) {
58 return (
"smtp login:" . $e->getMessage());
63 if( preg_match(
'/<(?<from>[^>]*)>/',
$from, $reg) ) {
64 $smtp_from = $reg[
'from'];
66 if (PEAR::isError($smtp->mailFrom($smtp_from))) {
67 return (
"Unable to set sender to <$smtp_from>");
70 foreach ($rcpt as $v) {
73 if (preg_match(
"/<([^>]*)>/", $v, $reg)) {
76 if (PEAR::isError($res = $smtp->rcptTo($v))) {
77 return (
"Unable to add recipient <$v>: " . $res->getMessage());
81 setlocale(LC_TIME,
'C');
85 if (is_a($mimemail,
'Fdl_Mail_mimePart')) {
87 $mm =
new Mail_Mime();
88 $mm->_build_params[
'head_charset'] =
'UTF-8';
95 $email = $mimemail->encode();
96 if (PEAR::isError($email)) {
97 $err = sprintf(
"Error encoding Fdl_Mail_mimePart : %s", $email->message);
98 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" " .
$err);
102 $txtHeaders = $mm->txtHeaders(array_merge($email[
'headers'], array(
105 'Date' => strftime(
"%a, %d %b %Y %H:%M:%S %z", time()) ,
106 'Message-Id' => sprintf(
"<%s@%s>", strftime(
"%Y%M%d%H%M%S-", time()) . rand(1, 65535) , $host) ,
107 'User-Agent' => sprintf(
"Dynacase Platform %s",
getParam(
'VERSION'))
110 $data = $txtHeaders . $mm->_build_params[
'eol'] . $email[
'body'];
113 $body = $mimemail->get();
115 $xh[
'Date'] = strftime(
"%a, %d %b %Y %H:%M:%S %z", time());
118 $xh[
'Message-Id'] =
'<' . strftime(
"%Y%M%d%H%M%S-", time()) . rand(1, 65535) .
"@$host>";
120 $xh[
'User-Agent'] = sprintf(
"Dynacase Platform %s",
getParam(
'VERSION'));
122 $h = $mimemail->headers($xh);
123 if ($multipart) $h[
'Content-Type'] = str_replace(
"mixed", $multipart, $h[
'Content-Type']);
125 foreach ($h as $k => $v) {
126 $data.=
"$k: $v\r\n";
129 $data.=
"\r\n" . $body;
132 if (PEAR::isError($smtp->data($data))) {
133 return (
"Unable to send data");
158 function addAttachment(
$file, $c_type =
'application/octet-stream',
$name =
'', $isfilename =
true, $encoding =
'base64', $cid =
'', $charset =
"UTF-8")
160 $filedata = ($isfilename ===
true) ? $this->_file2str(
$file) :
$file;
161 if ($isfilename ===
true) {
168 return PEAR::raiseError(
'The supplied filename for the attachment can\'t be empty');
170 if (PEAR::isError($filedata)) {
174 $this->_parts[] = array(
177 'charset' => $charset,
179 'encoding' => $encoding
184 function addAttachmentInline(
$file, $c_type =
'application/octet-stream',
$name =
'', $isfilename =
true, $encoding =
'base64', $cid =
'', $charset =
"UTF-8")
186 $filedata = ($isfilename ===
true) ? $this->_file2str(
$file) :
$file;
187 if ($isfilename ===
true) {
194 return PEAR::raiseError(
'The supplied filename for the attachment can\'t be empty');
196 if (PEAR::isError($filedata)) {
200 $this->_parts[] = array(
203 'charset' => $charset,
205 'encoding' => $encoding,
206 'disposition' =>
'inline',
222 $params[
'content_type'] =
$value[
'c_type'];
223 $params[
'encoding'] =
$value[
'encoding'];
224 $params[
'dfilename'] =
$value[
'name'];
225 $params[
'filename'] =
$value[
'name'];
226 $params[
'charset'] =
$value[
'charset'];
228 if (isset(
$value[
'disposition'])) {
229 $params[
'disposition'] =
$value[
'disposition'];
231 $params[
'disposition'] =
'attachment';
234 if (isset(
$value[
'cid'])) {
235 $params[
'cid'] =
$value[
'cid'];
238 if (isset(
$value[
'name_encoding'])) {
239 $params[
'name_encoding'] =
$value[
'name_encoding'];
241 $params[
'name_encoding'] =
'quoted-printable';
244 if (isset(
$value[
'filename_encoding'])) {
245 $params[
'filename_encoding'] =
$value[
'filename_encoding'];
247 $params[
'filename_encoding'] =
'quoted-printable';
250 $obj->addSubpart(
$value[
'body'], $params);
254 parent::Mail_mime($crlf);
255 $this->_build_params[
'html_charset'] =
'UTF-8';
256 $this->_build_params[
'text_charset'] =
'UTF-8';
257 $this->_build_params[
'head_charset'] =
'UTF-8';
268 if (isset($params[
'filename'])) {
269 $this->_filename = $params[
'filename'];
270 } elseif (isset($params[
'dfilename'])) {
271 $this->_filename = $params[
'dfilename'];
274 parent::Mail_mimePart($body, $params);
279 if (!property_exists(
'Mail_mimePart',
'_body_file') && isset($params[
'body_file'])) {
281 $body = file_get_contents($params[
'body_file']);
282 unset($params[
'body_file']);
285 return $this->_subparts[count($this->_subparts) - 1];
290 if (!property_Exists(
'Mail_mimePart',
'_body_file')) {
292 $this->_body = file_get_contents(
$file);
294 $this->_body_file =
$file;
304 include_once (
'WHAT/Lib.Common.php');
308 $msg->setValue(
"emsg_from",
$from);
310 $msg->setValue(
"emsg_subject",
$subject);
312 $msg->setValue(
"emsg_refid",
$doc->id);
313 $msg->profid =
$doc->profid;
316 foreach (explode(
',',
$to) as $v) {
317 if ($v) $msg->addArrayRow(
"emsg_t_recipient", array(
318 "emsg_sendtype" =>
"to",
319 "emsg_recipient" => $v
322 foreach (explode(
',',
$cc) as $v) {
323 if ($v) $msg->addArrayRow(
"emsg_t_recipient", array(
324 "emsg_sendtype" =>
"cc",
325 "emsg_recipient" => $v
328 foreach (explode(
',',
$bcc) as $v) {
329 if ($v) $msg->addArrayRow(
"emsg_t_recipient", array(
330 "emsg_sendtype" =>
"bcc",
331 "emsg_recipient" => $v
335 if (is_a($mimemail,
'Fdl_Mail_mimePart')) {
337 $partList = array(&$mimemail
340 while ($i < count($partList)) {
341 if (count($partList[$i]->_subparts) <= 0) {
345 $multipart = $partList[$i];
346 array_splice($partList, $i, 1);
347 foreach ($multipart->_subparts as & $part) {
348 $partList[] = & $part;
354 foreach ($partList as $i => & $part) {
355 if (preg_match(
"|^text/plain|", $part->_headers[
'Content-Type'])) {
357 array_splice($partList, $i, 1);
364 foreach ($partList as $i => & $part) {
365 if (preg_match(
"|^text/html|", $part->_headers[
'Content-Type'])) {
367 array_splice($partList, $i, 1);
374 if ($textPart !== null) {
375 if ($textPart->_body_file !=
'') {
376 $textBody = file_get_contents($textPart->_body_file);
378 $textBody = $textPart->_body;
380 $msg->setValue(
'emsg_textbody', $textBody);
384 if ($htmlPart !== null) {
385 if ($htmlPart->_body_file !=
'') {
386 $htmlBody = file_get_contents($htmlPart->_body_file);
388 $htmlBody = $htmlPart->_body;
390 $msg->setValue(
'emsg_htmlbody', $htmlBody);
393 foreach ($partList as $i => & $part) {
394 $tmpfile = tempnam(
getTmpDir() ,
'fdl_attach');
395 if ($part->_body_file !=
'') {
396 copy($part->_body_file, $tmpfile);
398 file_put_contents($tmpfile, $part->_body);
400 $msg->storeFile(
'emsg_attach', $tmpfile, $part->_filename, $i);
410 if ($htmlPart !== null && $htmlBody !=
'') {
412 foreach ($partList as $i => & $part) {
413 $cid = preg_replace(
'/^<(.+)>$/',
'\1', $part->_headers[
'Content-ID']);
415 $htmlBody = str_replace(sprintf(
"cid:%s", $cid) , $msg->getfileLink(
'emsg_attach', $i) , $htmlBody);
420 $msg->disableEditControl();
421 $msg->setValue(
'emsg_htmlbody', $htmlBody);
422 $err = $msg->modify(
true);
423 $msg->enableEditControl();
433 $msg->setValue(
"emsg_textbody", $mimemail->_txtbody);
434 $msg->setValue(
"emsg_htmlbody", $mimemail->_htmlbody);
435 $linkedbody = $mimemail->_htmlbody;
436 foreach ($mimemail->_parts as $k => $v) {
437 $tmpfile = tempnam(
getTmpDir() ,
'fdl_attach');
438 file_put_contents($tmpfile, $v[
"body"]);
439 $msg->storeFile(
"emsg_attach", $tmpfile, $v[
"name"], $k);
446 $linkedbody = $mimemail->_htmlbody;
447 foreach ($mimemail->_parts as $k => $v) {
448 $linkedbody = str_replace(
"cid:" . $v[
"cid"], $msg->getFileLink(
"emsg_attach", $k) , $linkedbody);
450 $msg->disableEditControl();
451 $msg->setValue(
"emsg_htmlbody", $linkedbody);
452 $err = $msg->modify(
true);