From 1cce044c5983a6522024ad623d7daec93c280b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20Wei=C3=9F?= Date: Wed, 23 Aug 2006 19:03:25 +0000 Subject: [PATCH] add new feature: mails can now be saved as infologs --- infolog/inc/class.boinfolog.inc.php | 75 +++++++++++++++++++ infolog/inc/class.uiinfolog.inc.php | 109 +++++++++++++++++++++++++++- infolog/setup/phpgw_de.lang | 3 + infolog/setup/phpgw_en.lang | 1 + 4 files changed, 186 insertions(+), 2 deletions(-) diff --git a/infolog/inc/class.boinfolog.inc.php b/infolog/inc/class.boinfolog.inc.php index 86b7bc8bcd..0a4f9335c7 100644 --- a/infolog/inc/class.boinfolog.inc.php +++ b/infolog/inc/class.boinfolog.inc.php @@ -598,6 +598,81 @@ return $ret; } + + /** + * imports a mail identified by uid as infolog + * + * @author Cornelius Weiss + * @todo search if infolog with from and subject allready exists ->appned body & inform user + * @param string $_email_address rfc822 conform emailaddresses + * @param string $_subject + * @param string $_message + * @param array $_attachments + * @param string $_date + * @return array $content array for uiinfolog + */ + function import_mail($_email_address,$_subject,$_message,$_attachments,$_date) + { + $address_array = imap_rfc822_parse_adrlist($_email_address,''); + foreach ((array)$address_array as $address) + { + $email[] = $emailadr = sprintf('%s@%s', + trim($address->mailbox), + trim($address->host)); + $name[] = !empty($address->personal) ? $address->personal : $emailadr; + } + + $info = array( + 'info_type' => isset($this->enums['type']['email']) ? 'email' : 'note', + 'info_from' => implode(',',$name), + 'info_addr' => implode(',',$email), + 'info_subject' => $_subject, + 'info_des' => $_message, + 'info_startdate' => $_date, + 'info_status' => 'done', + 'info_priority' => 1, + 'info_percent' => 100, + 'referer' => false, + 'link_to' => array( + 'to_id' => 0, + ), + ); + + // find the addressbookentry to link with + $addressbook = CreateObject('addressbook.bocontacts'); + $contacts = array(); + foreach ($email as $mailadr) + { + $contacts = array_merge($contacts,(array)$addressbook->search( + array( + 'email' => $mailadr, + 'email_home' => $mailadr + ),True,'','','',false,'OR',false,null,'',false)); + } + + if (empty($contacts) || empty($contacts[0])) + { + $info['msg'] = lang('Attension: No Contact with address %1 found.',$info['info_addr']); + } + else + { + foreach ((array)$contacts as $contact) + { + $this->link->link('infolog',$info['link_to']['to_id'],'addressbook',$contact['id']); + } + } + + if (is_array($_attachments)) + { + foreach ($_attachments as $attachment) + { + $this->link->link('infolog',$info['link_to']['to_id'],'file',$attachment); + } + } + + return $info; + } + /** * Hook called by link-class to include infolog in the appregistry of the linkage * diff --git a/infolog/inc/class.uiinfolog.inc.php b/infolog/inc/class.uiinfolog.inc.php index a7431d0cc3..125745b3b6 100644 --- a/infolog/inc/class.uiinfolog.inc.php +++ b/infolog/inc/class.uiinfolog.inc.php @@ -33,7 +33,8 @@ 'close' => True, 'admin' => True, 'hook_view' => True, - 'writeLangFile' => True + 'writeLangFile' => True, + 'import_mail' => True, ); /** * reference to the infolog preferences of the user @@ -633,7 +634,10 @@ else { $content['msg'] = lang('InfoLog entry saved'); - $content['js'] = "opener.location.href='".($link=$GLOBALS['egw']->link($referer,array('msg' => $content['msg'])))."';"; + if ($referer !== false) + { + $content['js'] = "opener.location.href='".($link=$GLOBALS['egw']->link($referer,array('msg' => $content['msg'])))."';"; + } } $content[$tabs] = $active_tab; if ((int) $content['pm_id'] != (int) $content['old_pm_id']) @@ -1057,6 +1061,107 @@ } } + /** + * imports a mail as infolog + * two possible calls: + * 1. with function args set. (we come from send mail) + * 2. with $_GET['uid] = someuid (we come from display mail) + * + * @author Cornelius Weiss + * @param unknown_type $_to_emailAddress + * @param string $_subject + * @param string $_body + * @param array $_attachments + * @param string $_date + */ + function import_mail($_to_emailAddress=false,$_subject=false,$_body=false,$_attachments=false,$_date=false) + { + $uid = $_GET['uid']; + $mailbox = $_GET['mailbox']; + + if (!empty($_to_emailAddress)) + { + $GLOBALS['egw_info']['flags']['currentapp'] = 'infolog'; + $GLOBALS['egw']->translation->add_app($GLOBALS['egw_info']['flags']['currentapp']); + echo ''; + + if (is_array($_attachments)) + { + foreach ($_attachments as $attachment) + { + $attachments[] = array( + 'name' => $attachment['name'], + 'mimeType' => $attachment['type'], + 'tmp_name' => $attachment['file'], + 'size' => $attachment['size'], + ); + } + } + + $this->edit($this->bo->import_mail( + implode(',',$_to_emailAddress),$_subject,$_body,$attachments,'' + )); + exit; + } + elseif ($uid && $mailbox) + { + $bofelamimail =& CreateObject('felamimail.bofelamimail',$GLOBALS['egw']->translation->charset()); + $bopreferences =& CreateObject('felamimail.bopreferences'); + $bofelamimail->openConnection(); + + $headers = $bofelamimail->getMessageHeader($mailbox,$uid); + $bodyParts = $bofelamimail->getMessageBody($uid,''); + $attachments = $bofelamimail->getMessageAttachments($uid); + + if (isset($headers->senderaddress)) $mailaddress = $bofelamimail->decode_header($headers->senderaddress); + elseif (isset($headers->fromaddress)) $mailaddress = $bofelamimail->decode_header($headers->fromaddress); + + $subject = $bofelamimail->decode_header($headers->Subject); + + // this should be a method of felamimail! + // We also need a html2text converter there! + for($i=0; $itranslation->convert($bodyParts[$i]['body'], $bodyParts[$i]['charSet']); + $newBody = explode("\n",$newBody); + // create it new, with good line breaks + reset($newBody); + while(list($key,$value) = @each($newBody)) + { + $value .= "\n"; + $bodyAppend = $bofelamimail->wordwrap($value,75,"\n"); + $message .= $bodyAppend; + } + } + + if (is_array($attachments)) + { + foreach ($attachments as $num => $attachment) + { + $attachments[$num] = array_merge($attachments[$num],$bofelamimail->getAttachment($_uid, $attachment['partID'])); + $attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_"); + $tmpfile = fopen($attachments[$num]['tmp_name'],'w'); + fwrite($tmpfile,$attachments[$num]['attachment']); + fclose($tmpfile); + unset($attachments[$num]['attachment']); + } + } + + return $this->edit($this->bo->import_mail( + $mailaddress, + $subject, + $message, + $attachments, + strtotime($headers->date) + )); + } + $GLOBALS['egw']->common->egw_header(); + echo ""; + $GLOBALS['egw']->common->egw_exit(); + exit; + } + /** * writes langfile with all templates and messages registered here * diff --git a/infolog/setup/phpgw_de.lang b/infolog/setup/phpgw_de.lang index 1d38686225..f9f385c947 100644 --- a/infolog/setup/phpgw_de.lang +++ b/infolog/setup/phpgw_de.lang @@ -36,6 +36,7 @@ apply the changes infolog de are you shure you want to delete this entry ? infolog de Sind Sie sicher, dass Sie diesen Eintrag löschen wollen? attach a file infolog de Datei anhängen attach file infolog de Datei anhängen +attension: no contact with address %1 found. infolog de Achtung: Kein Kontakt mit der Adresse %1 gefunden! back to main list infolog de Zurück zur Gesamtliste billed infolog de abgerechnet both infolog de Annahme+erledigt @@ -207,6 +208,7 @@ project settings: price, times infolog de Einstellungen zum Projekt: Preis, Zeit re: infolog de Re: read one record by passing its id. infolog de Einen Datensatz spezifiziert durch seine id lesen. read rights (default) infolog de Leserechte (Vorgabe) +reg. expr. for local ip's
eg. ^192.168.1. infolog de reg. Ausdr. für lokale IP's
^192\.168\.1\. reg. expr. for local ip's
eg. ^192\.168\.1\. infolog de reg. Ausdr. für lokale IP's
^192\.168\.1\. remark infolog de Bemerkung remove this link (not the entry itself) infolog de Diese Verknüpfung lösen (nicht den Eintrag selbst) @@ -285,6 +287,7 @@ urgency infolog de Priorit urgent infolog de Dringend used time infolog de benötigte Zeit valid path on clientside
eg. \\server\share or e:\ infolog de gültiger Pfad clientseitig
zB. \\Server\Share oder e:\ +valid path on clientside
eg. \servershare or e: infolog de gültiger Pfad clientseitig
zB. \\Server\Share oder e:\ values for selectbox infolog de Werte für die Auswahlbox view all subs of this entry infolog de alle Untereinträge dieses Eintrag anzeigen view other subs infolog de andere Untereinträge anzeigen diff --git a/infolog/setup/phpgw_en.lang b/infolog/setup/phpgw_en.lang index 60fb42929d..ae35de3987 100644 --- a/infolog/setup/phpgw_en.lang +++ b/infolog/setup/phpgw_en.lang @@ -36,6 +36,7 @@ apply the changes infolog en Apply the changes are you shure you want to delete this entry ? infolog en Are you sure you want to delete this entry ? attach a file infolog en Attach a file attach file infolog en Attach file +attension: no contact with address %1 found. infolog en Attension: No Contact with address %1 found. back to main list infolog en Back to main list billed infolog en billed both infolog en both