add new feature: mails can now be saved as infologs

This commit is contained in:
Cornelius Weiß 2006-08-23 19:03:25 +00:00
parent f45b9edc35
commit 1cce044c59
4 changed files with 186 additions and 2 deletions

View File

@ -598,6 +598,81 @@
return $ret;
}
/**
* imports a mail identified by uid as infolog
*
* @author Cornelius Weiss <nelius@cwtech.de>
* @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
*

View File

@ -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 <nelius@cwtech.de>
* @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 '<script>window.resizeTo(750,550);</script>';
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; $i<count($bodyParts); $i++)
{
// add line breaks to $bodyParts
$newBody = $GLOBALS['egw']->translation->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 "<script> window.close(); alert('Error: no mail (Mailbox / UID) given!');</script>";
$GLOBALS['egw']->common->egw_exit();
exit;
}
/**
* writes langfile with all templates and messages registered here
*

View File

@ -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<br>eg. ^192.168.1. infolog de reg. Ausdr. für lokale IP's<br>^192\.168\.1\.
reg. expr. for local ip's<br>eg. ^192\.168\.1\. infolog de reg. Ausdr. für lokale IP's<br>^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<br>eg. \\server\share or e:\ infolog de gültiger Pfad clientseitig<br>zB. \\Server\Share oder e:\
valid path on clientside<br>eg. \servershare or e: infolog de gültiger Pfad clientseitig<br>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

View File

@ -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