예제 #1
0
 /**
  * @param Account $_account
  * @param XmlDocument $_xmlObj
  * @return WebMailMessage
  */
 function &CreateMessage(&$_account, &$_xmlObj, &$_xmlRes)
 {
     $_messageNode =& $_xmlObj->XmlRoot->GetChildNodeByTagName('message');
     $_headersNode =& $_messageNode->GetChildNodeByTagName('headers');
     $_message = new WebMailMessage();
     $GLOBALS[MailDefaultCharset] = $_account->GetUserCharset();
     $GLOBALS[MailInputCharset] = $_account->GetUserCharset();
     $GLOBALS[MailOutputCharset] = $_account->GetDefaultOutCharset();
     $_message->Headers->SetHeaderByName(MIMEConst_MimeVersion, '1.0');
     $_message->Headers->SetHeaderByName(MIMEConst_XMailer, XMAILERHEADERVALUE);
     $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
     if (null !== $ip) {
         $_message->Headers->SetHeaderByName(MIMEConst_XOriginatingIp, $ip);
     }
     $_fromAcctId = $_messageNode->GetAttribute('from_acct_id', -1);
     $_message->IdMsg = $_messageNode->GetAttribute('id', -1);
     $_message->SetPriority($_messageNode->GetAttribute('priority', 3));
     $_message->SetSensivity($_messageNode->GetAttribute('sensivity', MIME_SENSIVITY_NOTHING));
     $_message->Uid = $_messageNode->GetChildValueByTagName('uid');
     $_serverAddr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['SERVER_NAME'] : 'cantgetservername';
     $_message->Headers->SetHeaderByName(MIMEConst_MessageID, '<' . substr(session_id(), 0, 7) . '.' . md5(time()) . '@' . $_serverAddr . '>');
     if ($_fromAcctId > 0) {
         $_fromAcct = null;
         if ($_account->Id == $_fromAcctId) {
             $_fromAcct = $_account;
         } else {
             CXmlProcessing::CheckAccountAccess($_fromAcctId, $_xmlRes);
             $_fromAcct = CXmlProcessing::AccountCheckAndLoad($_xmlRes, $_fromAcctId, false, false);
         }
         if ($_fromAcct) {
             $email = $_fromAcct->GetFriendlyEmail();
             /* custom class */
             wm_Custom::StaticUseMethod('ChangeAccountEmailToFake', array(&$email));
             $_message->SetFromAsString(ConvertUtils::WMBackHtmlSpecialChars($email));
         }
     } else {
         $_temp = $_headersNode->GetChildValueByTagName('from');
         if ($_temp) {
             /* custom class */
             wm_Custom::StaticUseMethod('ChangeAccountEmailToFake', array(&$_temp));
             $_message->SetFromAsString(ConvertUtils::WMBackHtmlSpecialChars($_temp));
         }
     }
     $_temp = $_headersNode->GetChildValueByTagName('to');
     if ($_temp) {
         $_message->SetToAsString(ConvertUtils::WMBackHtmlSpecialChars($_temp));
     }
     $_temp = $_headersNode->GetChildValueByTagName('cc');
     if ($_temp) {
         $_message->SetCcAsString(ConvertUtils::WMBackHtmlSpecialChars($_temp));
     }
     $_temp = $_headersNode->GetChildValueByTagName('bcc');
     if ($_temp) {
         $_message->SetBccAsString(ConvertUtils::WMBackHtmlSpecialChars($_temp));
     }
     $_temp = $_headersNode->GetChildValueByTagName('mailconfirmation');
     if ($_temp) {
         /* custom class */
         wm_Custom::StaticUseMethod('ChangeAccountEmailToFake', array(&$_temp));
         $_message->SetReadMailConfirmationAsString(ConvertUtils::WMBackHtmlSpecialChars($_temp));
     }
     $_message->SetSubject(ConvertUtils::WMBackHtmlSpecialChars($_headersNode->GetChildValueByTagName('subject')));
     $_message->SetDate(new CDateTime(time()));
     $_bodyNode =& $_messageNode->GetChildNodeByTagName('body');
     if (isset($_bodyNode->Attributes['is_html']) && $_bodyNode->Attributes['is_html']) {
         $_message->TextBodies->HtmlTextBodyPart = ConvertUtils::AddHtmlTagToHtmlBody(str_replace("\n", CRLF, str_replace("\r", '', ConvertUtils::BackImagesToHtmlBody(ConvertUtils::WMBackHtmlNewCode($_bodyNode->Value)))));
         $_message->TextBodies->PlainTextBodyPart = $_message->TextBodies->HtmlToPlain();
     } else {
         $_message->TextBodies->PlainTextBodyPart = str_replace("\n", CRLF, str_replace("\r", '', ConvertUtils::WMBackHtmlNewCode($_bodyNode->Value)));
     }
     $_attachmentsNode =& $_messageNode->GetChildNodeByTagName('attachments');
     if ($_attachmentsNode != null) {
         $tempFiles =& CTempFiles::CreateInstance($_account);
         $_log =& CLog::CreateInstance();
         $_attachmentsKeys = array_keys($_attachmentsNode->Children);
         foreach ($_attachmentsKeys as $_key) {
             $_attachNode =& $_attachmentsNode->Children[$_key];
             $_tempName = $_attachNode->GetChildValueByTagName('temp_name');
             $_fileName = $_attachNode->GetChildValueByTagName('name');
             $_attachCid = 'attach.php?img&amp;tn=' . $_tempName . '&amp;filename=' . $_fileName;
             $_replaceCid = md5(time() . $_fileName);
             $_mime_type = $_attachNode->GetChildValueByTagName('mime_type');
             if ($_mime_type === '') {
                 $_mime_type = ConvertUtils::GetContentTypeFromFileName($_fileName);
             }
             $_isInline = (bool) $_attachNode->GetAttribute('inline', false);
             if (!$_message->Attachments->AddFromBinaryBody($tempFiles->LoadFile($_attachNode->GetChildValueByTagName('temp_name')), $_fileName, $_mime_type, $_isInline)) {
                 $_log->WriteLine('Error Add tempfile in message: ' . getGlobalError(), LOG_LEVEL_ERROR);
             }
             if (isset($_bodyNode->Attributes['is_html']) && $_bodyNode->Attributes['is_html']) {
                 if (strpos($_message->TextBodies->HtmlTextBodyPart, $_attachCid) !== false) {
                     $_attachment =& $_message->Attachments->GetLast();
                     if ($_attachment) {
                         $_attachment->MimePart->Headers->SetHeaderByName(MIMEConst_ContentID, '<' . $_replaceCid . '>');
                         $_message->TextBodies->HtmlTextBodyPart = str_replace($_attachCid, 'cid:' . $_replaceCid, $_message->TextBodies->HtmlTextBodyPart);
                         $_attachname = ConvertUtils::EncodeHeaderString($_attachNode->GetChildValueByTagName('name'), $_account->GetUserCharset(), $GLOBALS[MailOutputCharset]);
                         $_attachment->MimePart->Headers->SetHeaderByName(MIMEConst_ContentDisposition, MIMEConst_InlineLower . ';' . CRLF . "\t" . MIMEConst_FilenameLower . '="' . $_attachname . '"', false);
                     }
                     unset($_attachment);
                 } else {
                     if ($_isInline) {
                         $_message->Attachments->DeleteLast();
                     }
                 }
             }
             unset($_attachNode);
         }
     }
     return $_message;
 }
예제 #2
0
 function DoOperationMessagesFunction()
 {
     $_dbStorage = $_settings = $_xmlObj = $_xmlRes = $_accountId = null;
     $this->_initFuncArgs($_dbStorage, $_settings, $_xmlObj, $_xmlRes, $_accountId);
     $_account =& CXmlProcessing::AccountCheckAndLoad($_xmlRes, $_accountId, false, false);
     $_processor = new MailProcessor($_account);
     $_messagesRequestNode =& $_xmlObj->XmlRoot->GetChildNodeByTagName('messages');
     if (!$_messagesRequestNode) {
         CXmlProcessing::PrintErrorAndExit(WebMailException, $_xmlRes);
     }
     $_getmsg = isset($_messagesRequestNode->Attributes['getmsg']) && $_messagesRequestNode->Attributes['getmsg'] == '1';
     $_folderNodeRequest =& $_messagesRequestNode->GetChildNodeByTagName('folder');
     if (isset($_folderNodeRequest->Attributes['id'])) {
         $_folder = new Folder($_accountId, $_folderNodeRequest->Attributes['id'], ConvertUtils::WMBackHtmlSpecialChars($_folderNodeRequest->GetChildValueByTagName('full_name')));
     } else {
         CXmlProcessing::PrintErrorAndExit(WebMailException, $_xmlRes);
     }
     $_processor->GetFolderInfo($_folder, true);
     $_toFolderNodeRequest =& $_messagesRequestNode->GetChildNodeByTagName('to_folder');
     if (isset($_toFolderNodeRequest->Attributes['id'])) {
         $_toFolder = new Folder($_accountId, $_toFolderNodeRequest->Attributes['id'], ConvertUtils::WMBackHtmlSpecialChars($_toFolderNodeRequest->GetChildValueByTagName('full_name')));
     } else {
         CXmlProcessing::PrintErrorAndExit(WebMailException, $_xmlRes);
     }
     $_processor->GetFolderInfo($_toFolder, true);
     $_operationNode = new XmlDomNode('operation_messages');
     $_toFolderNode = new XmlDomNode('to_folder', $_toFolder->FullName, true);
     $_toFolderNode->AppendAttribute('id', $_toFolder->IdDb);
     $_operationNode->AppendChild($_toFolderNode);
     $_folderNode = new XmlDomNode('folder', $_folder->FullName, true);
     $_folderNode->AppendAttribute('id', $_folder->IdDb);
     $_operationNode->AppendChild($_folderNode);
     $_messagesNode = new XmlDomNode('messages');
     $_messagesNode->AppendAttribute('getmsg', $_getmsg ? '1' : '0');
     $_messageIdUidSet = array();
     $_folders = array();
     $_messagesKeys = array_keys($_messagesRequestNode->Children);
     foreach ($_messagesKeys as $_nodeKey) {
         $_messageNode =& $_messagesRequestNode->Children[$_nodeKey];
         if ($_messageNode->TagName != 'message') {
             continue;
         }
         if (!isset($_messageNode->Attributes['id']) || !isset($_messageNode->Attributes['charset']) || !isset($_messageNode->Attributes['size'])) {
             continue;
         }
         $_msgId = $_messageNode->Attributes['id'];
         $_msgCharset = $_messageNode->Attributes['charset'];
         $_msgSize = $_messageNode->Attributes['size'];
         $_msgUid = $_messageNode->GetChildValueByTagName('uid', true);
         $_msgFolder =& $_messageNode->GetChildNodeByTagName('folder');
         if (!isset($_msgFolder->Attributes['id'])) {
             continue;
         }
         $_msgFolderId = $_msgFolder->Attributes['id'];
         $_folders[$_msgFolderId] = $_msgFolder->GetChildValueByTagName('full_name', true);
         if (!isset($_messageIdUidSet[$_msgFolderId])) {
             $_messageIdUidSet[$_msgFolderId] = array();
         }
         $_messageIdUidSet[$_msgFolderId][$_msgId] = $_msgUid;
         $_message = new XmlDomNode('message');
         $_message->AppendAttribute('id', $_msgId);
         $_message->AppendAttribute('charset', $_msgCharset);
         $_message->AppendAttribute('size', $_msgSize);
         $_message->AppendChild(new XmlDomNode('uid', $_msgUid, true));
         $_msgFolderNode = new XmlDomNode('folder', $_folders[$_msgFolderId], true);
         $_msgFolderNode->AppendAttribute('id', $_msgFolderId);
         $_message->AppendChild($_msgFolderNode);
         $_messagesNode->AppendChild($_message);
         unset($_messageNode, $_msgFolder, $_message, $_msgFolderNode);
     }
     $_operationNode->AppendChild($_messagesNode);
     $_errorString = $_typeString = '';
     $_request = $_xmlObj->GetParamValueByName('request');
     switch ($_request) {
         case 'mark_all_read':
             $_messageIdUidSet = null;
             if ($_processor->SetFlags($_messageIdUidSet, $_folder, MESSAGEFLAGS_Seen, ACTION_Set)) {
                 $_typeString = 'mark_all_read';
             } else {
                 $_errorString = PROC_CANT_MARK_ALL_MSG_READ;
             }
             break;
         case 'mark_all_unread':
             $_messageIdUidSet = null;
             if ($_processor->SetFlags($_messageIdUidSet, $_folder, MESSAGEFLAGS_Seen, ACTION_Remove)) {
                 $_typeString = 'mark_all_unread';
             } else {
                 $_errorString = PROC_CANT_MARK_ALL_MSG_UNREAD;
             }
             break;
         case 'purge':
             if (!$_settings->Imap4DeleteLikePop3 && $_account->MailProtocol == MAILPROTOCOL_IMAP4) {
                 if ($_processor->PurgeFolder($_folder)) {
                     $_typeString = 'purge';
                 } else {
                     $_errorString = PROC_CANT_PURGE_MSGS;
                 }
             } else {
                 if ($_processor->EmptyTrash()) {
                     $_typeString = 'purge';
                 } else {
                     $_errorString = PROC_CANT_PURGE_MSGS;
                 }
             }
             break;
         case 'clear_spam':
             if ($_processor->EmptySpam()) {
                 $_typeString = 'clear_spam';
             } else {
                 $_errorString = PROC_CANT_PURGE_MSGS;
             }
             break;
     }
     $_deleteFolderAppendError = false;
     $_foldersArray = array();
     foreach ($_folders as $_idFolder => $_fullNameFolder) {
         if (isset($_foldersArray[$_idFolder])) {
             $_folder =& $_foldersArray[$_idFolder];
         } else {
             $_folder = new Folder($_accountId, $_idFolder, $_fullNameFolder);
             $_processor->GetFolderInfo($_folder, true);
             $_foldersArray[$_idFolder] =& $_folder;
         }
         switch ($_request) {
             case 'no_move_delete':
                 if ($_processor->DeleteMessages($_messageIdUidSet[$_idFolder], $_folder, true)) {
                     $_typeString = 'no_move_delete';
                 } else {
                     $_errorString = PROC_CANT_DEL_MSGS;
                 }
                 break;
             case 'delete':
                 if ($_processor->DeleteMessages($_messageIdUidSet[$_idFolder], $_folder)) {
                     $_typeString = 'delete';
                 } else {
                     if ($_processor->IsMoveError) {
                         $_typeString = 'delete';
                         $_deleteFolderAppendError = true;
                     }
                     $_errorString = PROC_CANT_DEL_MSGS;
                 }
                 break;
             case 'undelete':
                 if ($_processor->SetFlags($_messageIdUidSet[$_idFolder], $_folder, MESSAGEFLAGS_Deleted, ACTION_Remove)) {
                     $_typeString = 'undelete';
                 } else {
                     $_errorString = PROC_CANT_UNDEL_MSGS;
                 }
                 break;
             case 'mark_read':
                 if ($_processor->SetFlags($_messageIdUidSet[$_idFolder], $_folder, MESSAGEFLAGS_Seen, ACTION_Set)) {
                     $_typeString = 'mark_read';
                 } else {
                     $_errorString = PROC_CANT_MARK_MSGS_READ;
                 }
                 break;
             case 'mark_unread':
                 if ($_processor->SetFlags($_messageIdUidSet[$_idFolder], $_folder, MESSAGEFLAGS_Seen, ACTION_Remove)) {
                     $_typeString = 'mark_unread';
                 } else {
                     $_errorString = PROC_CANT_MARK_MSGS_UNREAD;
                 }
                 break;
             case 'flag':
                 if ($_processor->SetFlags($_messageIdUidSet[$_idFolder], $_folder, MESSAGEFLAGS_Flagged, ACTION_Set)) {
                     $_typeString = 'flag';
                 } else {
                     $_errorString = PROC_CANT_SET_MSG_FLAGS;
                 }
                 break;
             case 'unflag':
                 if ($_processor->SetFlags($_messageIdUidSet[$_idFolder], $_folder, MESSAGEFLAGS_Flagged, ACTION_Remove)) {
                     $_typeString = 'unflag';
                 } else {
                     $_errorString = PROC_CANT_REMOVE_MSG_FLAGS;
                 }
                 break;
             case 'copy_to_folder':
                 // TODO
                 if ($_processor->MoveMessages($_messageIdUidSet[$_idFolder], $_folder, $_toFolder)) {
                     $_typeString = 'copy_to_folder';
                 } else {
                     $_errorString = PROC_CANT_CHANGE_MSG_FLD;
                 }
                 break;
             case 'move_to_folder':
                 if ($_processor->MoveMessages($_messageIdUidSet[$_idFolder], $_folder, $_toFolder)) {
                     $_typeString = 'move_to_folder';
                 } else {
                     $_errorString = PROC_CANT_CHANGE_MSG_FLD;
                 }
                 break;
             case 'spam':
                 if ($_processor->SpamMessages($_messageIdUidSet[$_idFolder], $_folder, true)) {
                     $_typeString = 'spam';
                 } else {
                     $_errorString = PROC_CANT_SET_MSG_AS_SPAM;
                 }
                 break;
             case 'not_spam':
                 if ($_processor->SpamMessages($_messageIdUidSet[$_idFolder], $_folder, false)) {
                     $_typeString = 'not_spam';
                 } else {
                     $_errorString = PROC_CANT_SET_MSG_AS_NOTSPAM;
                 }
                 break;
         }
         unset($_folder);
         if (strlen($_errorString) > 0) {
             break;
         }
     }
     if (strlen($_errorString) == 0 && strlen($_typeString) > 0) {
         $_operationNode->AppendAttribute('type', $_typeString);
         $_xmlRes->XmlRoot->AppendChild($_operationNode);
     } else {
         if ($_deleteFolderAppendError) {
             $_operationNode->AppendAttribute('type', $_typeString);
             $_messagesNode->AppendAttribute('no_move', '1');
             $_xmlRes->XmlRoot->AppendChild($_operationNode);
         } else {
             if (strlen($_errorString) == 0) {
                 $_errorString = WebMailException;
             }
             $_xmlRes->XmlRoot->AppendChild(new XmlDomNode('error', $_errorString, true));
         }
     }
 }