19 include_once (
"FDL/Class.Doc.php");
20 include_once (
"FDL/sendmail.php");
21 include_once (
"Class.MailAccount.php");
55 if ((is_array($raddr)) && (count($raddr) > 0)) {
56 foreach ($raddr as $k => $v) {
59 if ($tformat[$k] ==
"") $tformat[$k] =
"plain";
62 $tmailcc[$tformat[$k]][$v] = $v;
66 $tmailbcc[$tformat[$k]][$v] = $v;
70 $tmailto[$tformat[$k]][$v] = $v;
71 if ($idraddr[$k] > 0) $tuid[] = $idraddr[$k];
79 $tmailto[
"plain"][0] = $mt;
81 if ($oldcc) $tmailcc[
"plain"][0] = $oldcc;
83 if ($oldbcc) $tmailbcc[
"plain"][0] = $oldbcc;
84 if ($mailfrom ==
"") $mailfrom =
GetHttpVars(
"from");
93 $mailto = implode(
",", $tmailto[$format]);
94 $mailcc = implode(
",", $tmailcc[$format]);
95 $mailbcc = implode(
",", $tmailbcc[$format]);
97 setHttpVar(
"_mail_to", $mailto);
98 setHttpVar(
"_mail_cc", $mailcc);
99 setHttpVar(
"_mail_bcc", $mailbcc);
100 setHttpVar(
"_mail_from", $mailfrom);
101 if ($format ==
"link") setHttpVar(
"_mail_format",
"htmlnotif");
102 if (($mailto !=
"") || ($mailcc !=
"") || ($mailbcc !=
"")) {
109 if (
$err !=
"")
$action->exitError(sprintf(_(
"the document %s has not be sended :\n %s") ,
$doc->title,
$err));
110 elseif (!$sendedmail)
$action->addWarningMsg(sprintf(_(
"the document %s has not been sended : no recipient") ,
$doc->title));
113 foreach ($tuid as
$uid) {
116 $wuid =
getv($tu,
"us_whatid");
118 $err =
$doc->addUTag($wuid,
"TOVIEW");
131 $err =
sendCard(
$action,
GetHttpVars(
"id") ,
GetHttpVars(
"_mail_to",
'') ,
GetHttpVars(
"_mail_cc",
"") ,
GetHttpVars(
"_mail_subject") ,
GetHttpVars(
"zone") ,
GetHttpVars(
"ulink",
"N") ==
"Y",
GetHttpVars(
"_mail_cm",
"") ,
GetHttpVars(
"_mail_from",
"") ,
GetHttpVars(
"_mail_bcc",
"") ,
GetHttpVars(
"_mail_format",
"html") , $sendcopy, $addfiles, $userinfo,
GetHttpVars(
"_mail_savecopy",
"no") ==
"yes");
147 $err = $wdoc->ChangeState($state, _(
"email sended") ,
true);
151 $action->AddLogMsg(sprintf(_(
"the document %s is not related to a workflow") ,
$doc->title));
160 $addfiles = array() , $userinfo =
true, $savecopy =
false)
164 if ((!$viewonly) && (
$to ==
"") && (
$cc ==
"") && (
$bcc ==
""))
return _(
"mail dest is empty");
182 $dbaccess = $action->GetParam(
"FREEDOM_DB");
185 $ftitle = str_replace(array(
190 ) ,
"_", $doc->title);
191 $ftitle = str_replace(
"'",
"", $ftitle);
192 $ftitle = str_replace(
"\"",
"", $ftitle);
193 $ftitle = str_replace(
"&",
"", $ftitle);
195 $to = str_replace(
"\"",
"'",
$to);
197 $cc = str_replace(
"\"",
"'",
$cc);
198 $bcc = str_replace(
"\"",
"'",
$bcc);
201 $pubdir = $action->getParam(
"CORE_PUBDIR");
205 'content_type' =>
'multipart/mixed'
207 $multi_rel = $multi_mix->addSubpart(
'', array(
208 'content_type' =>
'multipart/related'
211 if ($sendercopy && $action->getParam(
"FDL_BCC") ==
"yes") {
214 if (
$bcc !=
"")
$bcc =
"$bcc,$umail";
215 else $bcc =
"$umail";
221 if (
$from ==
"")
$from = $action->user->login .
'@' . php_uname(
'n');
227 $layout =
"maildoc.xml";
229 $layout =
"mailnotification.xml";
230 $zonebodycard =
"FDL:MAILNOTIFICATION:S";
233 if ($zonebodycard ==
"") $zonebodycard = $doc->defaultmview;
234 if ($zonebodycard ==
"") $zonebodycard = $doc->defaultview;
236 if (preg_match(
"/[A-Z]+:[^:]+:S/", $zonebodycard, $reg)) $szone =
true;
237 if (preg_match(
"/[A-Z]+:[^:]+:T/", $zonebodycard, $reg)) setHttpVar(
"dochead",
"N");
238 if (preg_match(
"/[A-Z]+:[^:]+:B/", $zonebodycard, $reg)) $binary =
true;
242 $binfile = $doc->viewDoc($zonebodycard);
243 if (!is_file($binfile))
$err = $binfile;
246 $engine = $doc->getZoneTransform($zonebodycard);
248 include_once (
"FDL/Lib.Vault.php");
249 $outfile = uniqid(
getTmpDir() .
"/conv") .
".$engine";
260 $tplfile = $doc->getZoneFile($zonebodycard);
265 $multi_mix->addSubpart(
'', array(
266 'body_file' => $binfile,
267 'content_type' => $mime,
268 'charset' =>
'UTF-8',
269 'filename' => sprintf(
"%s.%s", $doc->title, $ext) ,
270 'dfilename' => sprintf(
"%s.%s", $doc->title, $ext) ,
271 'encoding' =>
'base64',
272 'name_encoding' =>
'quoted-printable',
273 'filename_encoding' =>
'quoted-printable',
274 'disposition' =>
'attachment'
277 $zonebodycard =
"FDL:EMPTY";
282 setHttpVar(
"target",
"mail");
283 if (preg_match(
"/html/",
$format, $reg)) {
285 if ($action->GetParam(
"CORE_URLINDEX") !=
"") {
286 $turl = parse_url($action->GetParam(
"CORE_URLINDEX"));
287 $url = $turl[
"scheme"] .
'://' . $turl[
"host"];
288 if (isset($turl[
"port"])) $url.=
':' . $turl[
"port"];
289 if (isset($turl[
"path"])) $url.= $turl[
"path"] .
"/";
291 $absurl = $action->GetParam(
"CORE_URLINDEX");
293 $absurl = $action->GetParam(
"CORE_ABSURL") .
"/";
294 $baseurl = $action->GetParam(
"CORE_ABSURL");
299 $sgen = $doc->viewDoc($zonebodycard,
"mail", $ulink,
false,
true);
301 $doc->lay->Set(
"absurl", $absurl);
302 $doc->lay->Set(
"baseurl", $baseurl);
303 $sgen = $doc->lay->gen();
306 $sgen = preg_replace(
"'<body([^>]*)>'i",
"<body \\1><P>$comment<P><HR>", $sgen);
312 $docmail->Set(
"TITLE", $doc->title);
313 $docmail->Set(
"ID", $doc->id);
314 $docmail->Set(
"zone", $zonebodycard);
315 $docmail->Set(
"absurl", $absurl);
316 $docmail->Set(
"baseurl", $baseurl);
318 $docmail->setBlockData(
"COMMENT", array(
323 $docmail->set(
"comment", nl2br(
$comment));
326 $sgen = $docmail->gen();
333 $sgen1 = preg_replace(
"/src=\"(FDL\/geticon[^\"]+)\"/ei",
"imgvaultfile('\\1')", $sgen);
335 $sgen1 = preg_replace(array(
336 "/SRC=\"([^\"]+)\"/e",
337 "/src=\"([^\"]+)\"/e"
338 ) ,
"srcfile('\\1')", $sgen1);
340 $pfout = uniqid(
getTmpDir() .
"/" . $doc->id);
341 $fout = fopen($pfout,
"w");
343 fwrite($fout, $sgen1);
348 if (preg_match(
"/pdf/",
$format, $reg)) {
352 $sgen = $doc->viewDoc($zonebodycard,
"mail",
false);
357 $docmail2->Set(
"zone", $zonebodycard);
358 $docmail2->Set(
"TITLE", $doc->title);
360 $sgen = $docmail2->gen();
362 $sgen2 = preg_replace(
"/src=\"([^\"]+)\"/ei",
"realfile('\\1')", $sgen);
364 $ppdf = uniqid(
getTmpDir() .
"/" . $doc->id) .
".pdf.html";
365 $fout = fopen($ppdf,
"w");
366 $sgen2 = preg_replace(
'/\xE2\x82\xAC/',
'€', $sgen2);
367 fwrite($fout, $sgen2);
373 if (preg_match(
"/html/",
$format, $reg)) {
374 $htmlPart = $multi_rel->addSubpart(
'', array(
375 'body_file' => $pfout,
376 'content_type' =>
'text/html',
377 'charset' =>
'UTF-8',
378 'encoding' =>
'quoted-printable',
379 'name_encoding' =>
'quoted-printable',
380 'filename_encoding' =>
'quoted-printable'
383 $multi_rel->addSubpart(
$comment, array(
384 'content_type' =>
'text/plain',
385 'charset' =>
'UTF-8',
386 'encoding' =>
'quoted-printable',
387 'name_encoding' =>
'quoted-printable',
388 'filename_encoding' =>
'quoted-printable'
395 if (preg_match_all(
"/(href|src)=\"cid:([^\"]*)\"/i", $sgen, $match)) {
397 $afiles = $doc->GetFileAttributes();
398 $taids = array_keys($afiles);
399 if (count($afiles) > 0) {
400 foreach ($tcids as $kf => $vaf) {
401 $tf = explode(
"+", $vaf);
402 if (count(
$tf) == 1) {
409 if (in_array($aid, $taids)) {
412 if ($afiles[$aid]->repeat) $va = $doc->getTValue($aid,
"", $index);
413 else $va = $doc->getValue($aid);
416 list($mime, $vid) = explode(
"|", $va);
419 if ($vf->Retrieve($vid, $info) ==
"") {
422 if (($mixed) && ($afiles[$aid]->type !=
"image")) $cidindex = $info->name;
423 $multi_mix->addSubpart(
'', array(
424 'body_file' => $info->path,
425 'content_type' => $info->mime_s ? $info->mime_s : $mime,
426 'charset' =>
'UTF-8',
427 'filename' => $info->name,
428 'dfilename' => $info->name,
429 'encoding' =>
'base64',
430 'name_encoding' =>
'quoted-printable',
431 'filename_encoding' =>
'quoted-printable',
432 'disposition' =>
'attachment',
443 if ($htmlPart !== null && $sgen1 !=
'' && $pfout !=
'') {
444 $htmlBody = preg_replace(
'|<a\s+(?:\w+="[^"]+")*\s*href="cid:[^"]+"[^>]*>([^<]*)</a>|si',
'\1', $sgen1);
445 $fout = fopen($pfout,
"w");
446 fwrite($fout, $htmlBody);
448 $htmlPart->setBodyFile($pfout);
452 if (preg_match(
"/html/",
$format, $reg)) {
456 list($mime, $vid) = explode(
"|", $va);
459 if ($vf->Retrieve($vid, $info) ==
"") {
460 $multi_rel->addSubpart(
'', array(
461 'body_file' => $info->path,
462 'content_type' => $info->mime_s ? $info->mime_s : $mime,
463 'charset' =>
'UTF-8',
464 'filename' => $info->name,
465 'dfilename' => $info->name,
466 'encoding' =>
'base64',
467 'name_encoding' =>
'quoted-printable',
468 'filename_encoding' =>
'quoted-printable',
469 'disposition' =>
'inline',
474 $icon = $doc->getIcon();
475 if (file_exists($pubdir .
"/$icon")) {
476 $multi_rel->addSubpart(
'', array(
477 'body_file' => sprintf(
"%s/%s", $pubdir, $icon) ,
478 'content_type' => sprintf(
"image/%s",
fileextension($icon)) ,
479 'charset' =>
'UTF-8',
480 'filename' =>
"icon",
481 'dfilename' =>
"icon",
482 'encoding' =>
'base64',
483 'name_encoding' =>
'quoted-printable',
484 'filename_encoding' =>
'quoted-printable',
485 'disposition' =>
'inline',
495 foreach ($ifiles as $k => $v) {
496 if (file_exists($pubdir .
"/$v")) {
498 $multi_rel->addSubpart(
'', array(
499 'body_file' => sprintf(
"%s/%s", $pubdir, $v) ,
501 'charset' =>
'UTF-8',
502 'filename' => basename($v) ,
503 'dfilename' => basename($v) ,
504 'encoding' =>
'base64',
505 'name_encoding' =>
'quoted-printable',
506 'filename_encoding' =>
'quoted-printable',
507 'disposition' =>
'inline',
513 foreach ($tfiles as $k => $v) {
514 if (file_exists($v)) {
516 $multi_rel->addSubpart(
'', array(
518 'content_type' => trim(shell_exec(sprintf(
"file --mime -b %s", escapeshellarg($v)))) ,
519 'charset' =>
'UTF-8',
522 'encoding' =>
'base64',
523 'name_encoding' =>
'quoted-printable',
524 'filename_encoding' =>
'quoted-printable',
525 'disposition' =>
'inline',
531 if (count($addfiles) > 0) {
532 foreach ($addfiles as $kf => $vf) {
533 if (count($vf) == 3) {
538 $fgen = $doc->viewDoc($fview,
"mail");
539 $fpname =
getTmpDir() .
"/" . str_replace(array(
544 ) ,
"_", uniqid($doc->id) . $fname);
545 if ($fp = fopen($fpname,
'w')) {
549 $fpst = stat($fpname);
550 if (is_array($fpst) && $fpst[
"size"] > 0) {
552 $multi_mix->addSubpart(
'', array(
553 'body_file' => $fpname,
554 'content_type' => $fmime,
555 'charset' =>
'UTF-8',
556 'filename' => $fname,
557 'dfilename' => $fname,
558 'encoding' =>
'base64',
559 'name_encoding' =>
'quoted-printable',
560 'filename_encoding' =>
'quoted-printable',
561 'disposition' =>
'attachment',
569 if (preg_match(
"/pdf/",
$format, $reg)) {
571 $fps = uniqid(
getTmpDir() .
"/" . $doc->id) .
"ps";
572 $fpdf = uniqid(
getTmpDir() .
"/" . $doc->id) .
"pdf";
573 $cmdpdf = sprintf(
"recode u8..l9 %s && html2ps -U -i 0.5 -b %s/ %s > %s && ps2pdf %s %s", escapeshellarg($ppdf) ,
574 escapeshellarg($pubdir) , escapeshellarg($ppdf) , escapeshellarg($fps) ,
575 escapeshellarg($fps) , escapeshellarg($fpdf)
577 system(($cmdpdf) , $status);
579 $multi_mix->addSubpart(
'', array(
580 'body_file' => $fpdf,
581 'content_type' =>
'application/pdf',
582 'charset' =>
'UTF-8',
583 'filename' => sprintf(
"%s.pdf", $doc->title) ,
584 'dfilename' => sprintf(
"%s.pdf", $doc->title) ,
585 'encoding' =>
'base64',
586 'name_encoding' =>
'quoted-printable',
587 'filename_encoding' =>
'quoted-printable',
588 'disposition' =>
'attachment'
591 $action->addlogmsg(sprintf(_(
"PDF conversion failed for %s") , $doc->title));
598 if (
$cc !=
"") $lsend = sprintf(
"%s and %s",
$to,
$cc);
600 $doc->addcomment(sprintf(_(
"sended to %s") , $lsend));
601 $action->addlogmsg(sprintf(_(
"sending %s to %s") , $doc->title, $lsend));
602 if ($userinfo) $action->addwarningmsg(sprintf(_(
"sending %s to %s") , $doc->title, $lsend));
604 $action->log->warning(
$err);
605 $action->addlogmsg(sprintf(_(
"%s cannot be sent") , $doc->title));
606 if ($userinfo) $action->addwarningmsg(sprintf(_(
"%s cannot be sent") , $doc->title));
607 if ($userinfo) $action->addwarningmsg(
$err);
610 if (isset($ftxt) && is_file($ftxt)) unlink($ftxt);
611 if (isset($fpdf) && is_file($fpdf)) unlink($fpdf);
612 if (isset($fps) && is_file($fps)) unlink($fps);
613 if (isset($pfout) && is_file($pfout)) unlink($pfout);
614 if (isset($ppdf) && is_file($ppdf)) unlink($ppdf);
615 if (isset($binfile) && is_file($binfile)) unlink($binfile);
617 $tmpfile = array_merge($tmpfile, $tfiles);
618 foreach ($tmpfile as $k => $v) {
619 if (file_exists($v) && (substr($v, 0, 9) ==
getTmpDir() .
"/")) unlink($v);
636 if (substr($src, 0, 3) ==
"cid")
return "src=\"$src\"";
637 if (substr($src, 0, 4) ==
"http") {
645 if (strlen($url) <= 0) {
648 if (strcmp(substr($src, 0, strlen($url)) , $url) == 0) {
650 $chopped_src = substr($src, strlen($url));
654 if ($chopped_src ==
'') {
655 return sprintf(
'src="%s"', $src);
660 if (preg_match(
"/(.*)(app=FDL.*action=EXPORTFILE.*)$/", $src, $reg)) {
661 return imgvaultfile(str_replace(
'&',
'&', $reg[2]));
664 if (!in_array(strtolower(
fileextension($src)) , $vext))
return "";
666 $ifiles[$src] = $src;
667 return "src=\"cid:$src\"";
674 $src =
"img" . count($tfiles);
675 $tfiles[$src] = $newfile;
676 return "src=\"cid:$src\" ";
684 include_once (
'FDL/Lib.Vault.php');
686 if (preg_match(
"/(.*)(app=FDL.*action=EXPORTFILE.*)docid=([^&]*)&/", $src, $reg)) {
687 $url = $action->getParam(
"CORE_OPENURL", $action->getParam(
"CORE_EXTERNURL"));
688 if (strstr($url,
'?')) $url.=
'&';
690 $token = $action->user->getUserToken(3600,
true, array(
692 "action" =>
"EXPORTFILE",
695 $url.=
"authtype=open&privateid=$token&";
698 if (!copy($url, $newfile)) {
703 if (preg_match(
"|^FDL/geticon\.php\?vaultid=(?P<vid>\d+)|", $src, $reg)) {
706 if (!copy($info->path, $newfile)) {
722 if ($src ==
"cid:icon") {
725 if (substr($src, 0, 4) ==
"cid:") $va = $doc->getValue(substr($src, 4));
726 elseif (preg_match(
"/(.*)(app=FDL.*action=EXPORTFILE.*)$/", $src, $reg)) {
727 $va =
copyvault(str_replace(
'&',
'&', $reg[2]));
733 list($mime, $vid) = explode(
"|", $va);
736 if ($vf->Retrieve($vid, $info) ==
"") {
741 if (file_exists($pubdir .
"/$va")) $f = $pubdir .
"/$va";
742 elseif (file_exists($pubdir .
"/Images/$va")) $f = $pubdir .
"/Images/$va";
743 elseif ((substr($va, 0, 12) ==
getTmpDir() .
'/img') && file_exists($va)) $f = $va;
749 if ($f)
return "src=\"$f\"";