diff --git a/felamimail/inc/class.bocompose.inc.php b/felamimail/inc/class.bocompose.inc.php
new file mode 100644
index 0000000000..faffc7ebfe
--- /dev/null
+++ b/felamimail/inc/class.bocompose.inc.php
@@ -0,0 +1,589 @@
+ True,
+ 'action' => True
+ );
+
+ var $attachments; // Array of attachments
+ var $preferences; // the prefenrences(emailserver, username, ...)
+
+ function bocompose($_composeID = '', $_charSet = 'iso-8859-1')
+ {
+ $this->displayCharset = strtolower($_charSet);
+ $this->bopreferences =& CreateObject('felamimail.bopreferences');
+ $this->bofelamimail =& CreateObject('felamimail.bofelamimail',$_charSet);
+ $this->preferences = $this->bopreferences->getPreferences();
+ $this->botranslation =& CreateObject('phpgwapi.translation');
+
+ if (!empty($_composeID))
+ {
+ $this->composeID = $_composeID;
+ $this->restoreSessionData();
+ }
+ }
+
+ /**
+ * adds uploaded files or files in eGW's temp directory as attachments
+ *
+ * It also stores the given data in the session
+ *
+ * @param array $_formData fields of the compose form (to,cc,bcc,reply_to,subject,body,priority,signature), plus data of the file (name,file,size,type)
+ */
+ function addAttachment($_formData)
+ {
+ $this->sessionData['to'] = $_formData['to'];
+ $this->sessionData['cc'] = $_formData['cc'];
+ $this->sessionData['bcc'] = $_formData['bcc'];
+ $this->sessionData['reply_to'] = $_formData['reply_to'];
+ $this->sessionData['subject'] = $_formData['subject'];
+ $this->sessionData['body'] = $_formData['body'];
+ $this->sessionData['priority'] = $_formData['priority'];
+ $this->sessionData['signature'] = $_formData['signature'];
+
+ #while(list($key,$value) = each($GLOBALS['egw_info']['user']))
+ #{
+ # print "$key: $value
";
+ #}
+
+ // to gard against exploidts the file must be either uploaded or be in the temp_dir
+ if ($_formData['size'] != 0 && (is_uploaded_file($_formData['file']) ||
+ realpath(dirname($_formData['file'])) == realpath($GLOBALS['egw_info']['server']['temp_dir'])))
+ {
+ // ensure existance of eGW temp dir
+ // note: this is different from apache temp dir,
+ // and different from any other temp file location set in php.ini
+ if (!file_exists($GLOBALS['egw_info']['server']['temp_dir']))
+ {
+ @mkdir($GLOBALS['egw_info']['server']['temp_dir'],0700);
+ }
+
+ // if we were NOT able to create this temp directory, then make an ERROR report
+ if (!file_exists($GLOBALS['egw_info']['server']['temp_dir']))
+ {
+ $alert_msg .= 'Error:'.'
'
+ .'Server is unable to access phpgw tmp directory'.'
'
+ .$GLOBALS['egw_info']['server']['temp_dir'].'
'
+ .'Please check your configuration'.'
'
+ .'
';
+ }
+
+ // sometimes PHP is very clue-less about MIME types, and gives NO file_type
+ // rfc default for unknown MIME type is:
+ $mime_type_default = 'application/octet-stream';
+ // so if PHP did not pass any file_type info, then substitute the rfc default value
+ if (trim($_formData['type']) == '')
+ {
+ $_formData['type'] = $mime_type_default;
+ }
+
+ $tmpFileName = $GLOBALS['egw_info']['server']['temp_dir'].
+ SEP.
+ $GLOBALS['egw_info']['user']['account_id'].
+ $this->composeID.
+ basename($_formData['file']);
+
+ if (is_uploaded_file($_formData['file']))
+ {
+ move_uploaded_file($_formData['file'],$tmpFileName); // requirement for safe_mode!
+ }
+ else
+ {
+ rename($_formData['file'],$tmpFileName);
+ }
+ $this->sessionData['attachments'][]=array
+ (
+ 'name' => $_formData['name'],
+ 'type' => $_formData['type'],
+ 'file' => $tmpFileName,
+ 'size' => $_formData['size']
+ );
+ }
+
+ $this->saveSessionData();
+ #print"
";print_r($this->sessionData);print""; + } + + function addMessageAttachment($_uid, $_partID, $_folder, $_name, $_size) + { + $this->sessionData['attachments'][]=array + ( + 'uid' => $_uid, + 'partID' => $_partID, + 'name' => $_name, + 'type' => 'message/rfc822', + 'size' => $_size, + 'folder' => $_folder + ); + + $this->saveSessionData(); + #print"
";print_r($this->sessionData);print""; + } + + function getAttachmentList() + { + } + + // create a hopefully unique id, to keep track of different compose windows + // if you do this, you are creating a new email + function getComposeID() + { + mt_srand((float) microtime() * 1000000); + $this->composeID = mt_rand (100000, 999999); + + $this->setDefaults(); + + return $this->composeID; + } + + function getErrorInfo() + { + if(isset($this->errorInfo)) + { + $errorInfo = $this->errorInfo; + unset($this->errorInfo); + return $errorInfo; + } + return false; + } + + function getForwardData($_uid, $_partID, $_folder) + { + $bofelamimail =& CreateObject('felamimail.bofelamimail',$this->displayCharset); + $bofelamimail->openConnection(); + + // get message headers for specified message + $headers = $bofelamimail->getMessageHeader($_uid, $_partID); + // check for Re: in subject header + $this->sessionData['subject'] = "[FWD] " . $bofelamimail->decode_header($headers->Subject); + if($headers->Size) + $size = $headers->Size; + else + $size = lang('unknown'); + + $this->addMessageAttachment($_uid, $_partID, + $_folder, + $bofelamimail->decode_header($headers->Subject), + $size); + + $bofelamimail->closeConnection(); + + $this->saveSessionData(); + } + + // $_mode can be: + // single: for a reply to one address + // all: for a reply to all + function getReplyData($_mode, $_uid, $_partID) + { + $bofelamimail =& CreateObject('felamimail.bofelamimail',$this->displayCharset); + $bofelamimail->openConnection(); + + // get message headers for specified message + $headers = $bofelamimail->getMessageHeader($_uid, $_partID); + + $this->sessionData['uid'] = $_uid; + + // check for Reply-To: header and use if available + if($headers->reply_toaddress) + { + $this->sessionData['to'] = $bofelamimail->decode_header(trim($headers->reply_toaddress)); + } + else + { + $this->sessionData['to'] = $bofelamimail->decode_header(trim($headers->fromaddress)); + } + + if($_mode == 'all') + { + #_debug_array($this->preferences); + // reply to any address which is cc, but not to my self + $oldCC = $bofelamimail->decode_header(trim($headers->ccaddress)); + $addressParts = imap_rfc822_parse_adrlist($oldCC, ''); + if (count($addressParts)>0) + { + while(list($key,$val) = each($addressParts)) + { + if($val->mailbox.'@'.$val->host == $this->preferences['emailAddress']) + { + continue; + } + if(!empty($this->sessionData['cc'])) $this->sessionData['cc'] .= ","; + if(!empty($val->personal)) + { + $this->sessionData['cc'] .= sprintf('"%s" <%s@%s>', + $val->personal, + $val->mailbox, + $val->host); + } + else + { + $this->sessionData['cc'] .= sprintf("%s@%s", + $val->mailbox, + $val->host); + } + } + } + + + // reply to any address which is to, but not to my self + $oldTo = $bofelamimail->decode_header(trim($headers->toaddress)); + $addressParts = imap_rfc822_parse_adrlist($oldTo, ''); + if (count($addressParts)>0) + { + while(list($key,$val) = each($addressParts)) + { + if($val->mailbox.'@'.$val->host == $this->preferences['emailAddress']) + { + continue; + } + #print $val->mailbox.'@'.$val->host."
".$newBody."
";print_r($this->sessionData);print""; + } + + function saveSessionData() + { + $GLOBALS['egw']->session->appsession('compose_session_data_'.$this->composeID,'',$this->sessionData); + } + + function send($_formData) + { + $bofelamimail =& CreateObject('felamimail.bofelamimail',$this->displayCharset); + $mail =& CreateObject('phpgwapi.phpmailer'); + + $this->sessionData['to'] = trim($_formData['to']); + $this->sessionData['cc'] = trim($_formData['cc']); + $this->sessionData['bcc'] = trim($_formData['bcc']); + $this->sessionData['reply_to'] = trim($_formData['reply_to']); + $this->sessionData['subject'] = trim($_formData['subject']); + $this->sessionData['body'] = $_formData['body']; + $this->sessionData['priority'] = $_formData['priority']; + $this->sessionData['signature'] = $_formData['signature']; + + + $userLang = $GLOBALS['egw_info']['user']['preferences']['common']['lang']; + $langFile = EGW_SERVER_ROOT."/phpgwapi/setup/phpmailer.lang-$userLang.php"; + if(file_exists($langFile)) + { + $mail->SetLanguage($userLang, EGW_SERVER_ROOT."/phpgwapi/setup/"); + } + else + { + $mail->SetLanguage("en", EGW_SERVER_ROOT."/phpgwapi/setup/"); + } + $mail->PluginDir = EGW_SERVER_ROOT."/phpgwapi/inc/"; + + #print $this->sessionData['uid']."