Пример #1
0
 /**
  * @return string
  */
 function ToString($doEncode = false)
 {
     $value = $this->Value;
     if ($doEncode) {
         if (!ConvertUtils::IsLatin($value)) {
             $value = ConvertUtils::EncodeHeaderString($value, $GLOBALS[MailInputCharset], $GLOBALS[MailOutputCharset], true);
         }
     }
     if ($this->Attribute != '' && $this->Value != '') {
         return sprintf('%s="%s"', $this->Attribute, $value);
     } elseif ($this->Attribute != '') {
         return $this->Attribute;
     } elseif ($this->Value != '') {
         return $value;
     }
     return '';
 }
Пример #2
0
 /**
  * @return string
  */
 function GetEncodedValue()
 {
     if ($this->IsParsed) {
         if ($this->IsEmailAddress()) {
             $addressCollection = new EmailAddressCollection($this->Value);
             return $addressCollection->ToString();
         }
         if ($this->IsSubject()) {
             return ConvertUtils::EncodeHeaderString($this->Value, $GLOBALS[MailInputCharset], $GLOBALS[MailOutputCharset], true);
         }
         if ($this->IsWithParameters()) {
             $parameterCollection = new HeaderParameterCollection($this->Value);
             return $parameterCollection->ToString(true);
         }
     }
     if (ConvertUtils::IsLatin($this->Value)) {
         return $this->Value;
     } else {
         return ConvertUtils::EncodeHeaderString($this->Value, $GLOBALS[MailInputCharset], $GLOBALS[MailOutputCharset]);
     }
 }
Пример #3
0
 /**
  * Returns the e-mail address as a string.
  * @return string
  */
 function ToString($changeCharset = true)
 {
     $result = '';
     if ($this->Email != '') {
         $NewDisplayName = substr($this->DisplayName, 0, 2) == '=?' ? $this->DisplayName : ConvertUtils::EncodeHeaderString($this->DisplayName, $GLOBALS[MailInputCharset], $GLOBALS[MailOutputCharset], $changeCharset);
         $NewRemarks = substr($this->Remarks, 0, 2) == '=?' ? $this->Remarks : ConvertUtils::EncodeHeaderString($this->Remarks, $GLOBALS[MailInputCharset], $GLOBALS[MailOutputCharset], $changeCharset);
         if ($this->DisplayName != '' && $this->Remarks != '') {
             $result = '"' . $NewDisplayName . '" ';
             if (strlen($NewDisplayName . $this->Email) > MIMEConst_LineLengthLimit) {
                 $result .= CRLF . "\t";
             }
             $result .= '<' . $this->Email . '> ';
             if (strlen($NewDisplayName . $this->Email) > MIMEConst_LineLengthLimit) {
                 if (strlen($this->Email . $NewRemarks) > MIMEConst_LineLengthLimit) {
                     $result .= CRLF . "\t";
                 }
             } else {
                 if (strlen($NewDisplayName . $this->Email . $NewRemarks) > MIMEConst_LineLengthLimit) {
                     $result .= CRLF . "\t";
                 }
             }
             $result .= '(' . $NewRemarks . ')';
         } elseif ($this->DisplayName != '') {
             $result = '"' . $NewDisplayName . '" ';
             if (strlen($NewDisplayName . $this->Email) > MIMEConst_LineLengthLimit) {
                 $result .= CRLF . "\t";
             }
             $result .= '<' . $this->Email . '>';
         } elseif ($this->Remarks != '') {
             $result = '<' . $this->Email . '>';
             if (strlen($this->Email . $NewRemarks) > MIMEConst_LineLengthLimit) {
                 $result .= CRLF . "\t";
             }
             $result .= '(' . $NewRemarks . ')';
         } else {
             $result = $this->Email;
         }
     } else {
         if ($this->DisplayName != '' && $this->Remarks == '') {
             $result = substr($this->DisplayName, 0, 2) == '=?' ? '"' . $this->DisplayName . '"' : '"' . ConvertUtils::EncodeHeaderString($this->DisplayName, $GLOBALS[MailInputCharset], $GLOBALS[MailOutputCharset], $changeCharset) . '"';
         } else {
             if ($this->DisplayName == '' && $this->Remarks != '') {
                 $result = substr($this->Remarks, 0, 2) == '=?' ? '(' . $this->Remarks . ')' : '(' . ConvertUtils::EncodeHeaderString($this->Remarks, $GLOBALS[MailInputCharset], $GLOBALS[MailOutputCharset], $changeCharset) . ')';
             }
         }
     }
     return $result;
 }
Пример #4
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;
 }
Пример #5
0
/**
 * @param Account $account
 * @param XmlDocument $xmlObj
 * @return WebMailMessage
 */
function &CreateMessage(&$account, &$xmlObj)
{
    global $log;
    $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, 'MailBee WebMail Pro PHP');
    $message->Headers->SetHeaderByName(MIMEConst_XOriginatingIp, isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0');
    $message->IdMsg = $messageNode->GetAttribute('id', -1);
    $message->SetPriority($messageNode->GetAttribute('priority', 3));
    $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 . '>');
    $temp = $headersNode->GetChildValueByTagName('from');
    if ($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));
    }
    $message->SetSubject(ConvertUtils::WMBackHtmlSpecialChars($headersNode->GetChildValueByTagName('subject')));
    $message->SetDate(new CDateTime(time()));
    $bodyNode =& $messageNode->GetChildNodeByTagName('body');
    if ($bodyNode->Attributes['is_html']) {
        $message->TextBodies->HtmlTextBodyPart = str_replace("\n", CRLF, str_replace("\r", '', ConvertUtils::WMBackHtmlNewCode($bodyNode->Value)));
    } else {
        $message->TextBodies->PlainTextBodyPart = str_replace("\n", CRLF, str_replace("\r", '', ConvertUtils::WMBackHtmlNewCode($bodyNode->Value)));
    }
    $attachmentsNode =& $messageNode->GetChildNodeByTagName('attachments');
    if ($attachmentsNode != null) {
        $fs =& new FileSystem(INI_DIR . '/temp', $account->Email, $account->Id);
        $attfolder =& new Folder($_SESSION[ACCOUNT_ID], -1, $_SESSION['attachtempdir']);
        foreach (array_keys($attachmentsNode->Children) as $key) {
            $attachNode =& $attachmentsNode->Children[$key];
            $attachCid = 'attach.php?tn=' . $attachNode->GetChildValueByTagName('temp_name');
            $replaceCid = md5(time() . $attachNode->GetChildValueByTagName('name'));
            $mime_type = $attachNode->GetChildValueByTagName('mime_type');
            if ($mime_type == '') {
                $mime_type = ConvertUtils::GetContentTypeFromFileName($attachNode->GetChildValueByTagName('name'));
            }
            if (!$message->Attachments->AddFromFile($fs->GetFolderFullPath($attfolder) . '/' . $attachNode->GetChildValueByTagName('temp_name'), $attachNode->GetChildValueByTagName('name'), $mime_type, (bool) $attachNode->Attributes['inline'])) {
                $log->WriteLine('Error Get tempfile for Attachment: ' . getGlobalError());
            }
            if ($bodyNode->Attributes['is_html']) {
                if (strpos($message->TextBodies->HtmlTextBodyPart, $attachCid) !== false) {
                    $attachment =& $message->Attachments->GetLast();
                    $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);
                }
            }
        }
    }
    return $message;
}
 function AddFromBodyStructure($attachname, $idx, $size, $encode, $contentId = null)
 {
     $attachname = ConvertUtils::EncodeHeaderString($attachname, $GLOBALS[MailInputCharset], 'utf-8');
     $mimetype = ConvertUtils::GetContentTypeFromFileName($attachname);
     $mimePart = new MimePart();
     $mimePart->BodyStructureIndex = $idx;
     $mimePart->BodyStructureSize = $size;
     $mimePart->BodyStructureEncode = $encode;
     $mimePart->Headers->SetHeaderByName(MIMEConst_ContentType, $mimetype . ';' . CRLF . "\t" . MIMEConst_NameLower . '="' . $attachname . '"', false);
     $mimePart->Headers->SetHeaderByName(MIMEConst_ContentTransferEncoding, MIMEConst_Base64Lower, false);
     $mimePart->Headers->SetHeaderByName(MIMEConst_ContentDisposition, MIMEConst_AttachmentLower . ';' . CRLF . "\t" . MIMEConst_FilenameLower . '="' . $attachname . '"', false);
     if (null !== $contentId) {
         $mimePart->Headers->SetHeaderByName(MIMEConst_ContentID, '<' . $contentId . '>', false);
     }
     $this->List->Add(new Attachment($mimePart, null !== $contentId));
     return true;
 }
Пример #7
0
/**
 * @param Account $account
 * @return WebMailMessage
 */
function &CreateMessageFromPost(&$account)
{
    $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, 'MailBee WebMail Pro PHP');
    $message->Headers->SetHeaderByName(MIMEConst_XOriginatingIp, isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0');
    $message->IdMsg = Post::val('m_id', -1);
    $message->SetPriority(Post::val('priority_input', 3));
    $message->DbPriority = Post::val('priority_input', 3);
    $message->Uid = Post::val('m_uid', '');
    $message->Headers->SetHeaderByName(MIMEConst_MessageID, '<' . substr(session_id(), 0, 7) . '.' . md5(time()) . '@' . $_SERVER['SERVER_NAME'] . '>');
    $temp = Post::val('from', '');
    if ($temp) {
        $message->SetFromAsString($temp);
    }
    $temp = Post::val('toemail', '');
    if ($temp) {
        $message->SetToAsString($temp);
    }
    $temp = Post::val('toCC', '');
    if ($temp) {
        $message->SetCcAsString($temp);
    }
    $temp = Post::val('toBCC', '');
    if ($temp) {
        $message->SetBccAsString($temp);
    }
    $temp = Post::val('subject', '');
    if ($temp) {
        $message->SetSubject($temp);
    }
    $message->SetDate(new CDateTime(time()));
    if (Post::val('ishtml', 0)) {
        $message->TextBodies->HtmlTextBodyPart = ConvertUtils::BackImagesToHtmlBody(Post::val('message', ''));
    } else {
        $message->TextBodies->PlainTextBodyPart = ConvertUtils::BackImagesToHtmlBody(Post::val('message', ''));
    }
    $attachments = Post::val('attachments');
    if ($attachments && is_array($attachments)) {
        $fs =& new FileSystem(INI_DIR . '/temp', $account->Email, $account->Id);
        $attfolder =& new Folder($account->Id, -1, Session::val('attachtempdir'));
        foreach ($attachments as $key => $value) {
            if (Session::val('attachtempdir')) {
                $attachCid = 'attach.php?tn=' . $key;
                $replaceCid = md5(time() . $value);
                $mime_type = ConvertUtils::GetContentTypeFromFileName($value);
                $message->Attachments->AddFromFile($fs->GetFolderFullPath($attfolder) . '/' . $key, $value, $mime_type, false);
                if (Post::val('ishtml', 0)) {
                    if (strpos($message->TextBodies->HtmlTextBodyPart, $attachCid) !== false) {
                        $attachment =& $message->Attachments->GetLast();
                        $attachment->MimePart->Headers->SetHeaderByName(MIMEConst_ContentID, '<' . $replaceCid . '>');
                        $message->TextBodies->HtmlTextBodyPart = str_replace($attachCid, 'cid:' . $replaceCid, $message->TextBodies->HtmlTextBodyPart);
                        $attachname = ConvertUtils::EncodeHeaderString($value, $account->GetUserCharset(), $GLOBALS[MailOutputCharset]);
                        $attachment->MimePart->Headers->SetHeaderByName(MIMEConst_ContentDisposition, MIMEConst_InlineLower . ';' . CRLF . "\t" . MIMEConst_FilenameLower . '="' . $attachname . '"', false);
                    }
                }
            }
        }
    }
    return $message;
}
 function AddFromBinaryBody($bbody, $attachname, $mimetype, $isInline)
 {
     if ($bbody) {
         $AttachType = $isInline ? MIMEConst_InlineLower : MIMEConst_AttachmentLower;
         $attachname = ConvertUtils::EncodeHeaderString($attachname, $GLOBALS[MailInputCharset], $GLOBALS[MailOutputCharset]);
         $mimePart = new MimePart();
         $mimePart->Headers->SetHeaderByName(MIMEConst_ContentType, $mimetype . ';' . CRLF . "\t" . MIMEConst_NameLower . '="' . $attachname . '"', false);
         $mimePart->Headers->SetHeaderByName(MIMEConst_ContentTransferEncoding, MIMEConst_Base64Lower, false);
         $mimePart->Headers->SetHeaderByName(MIMEConst_ContentDisposition, $AttachType . ';' . CRLF . "\t" . MIMEConst_FilenameLower . '="' . $attachname . '"', false);
         $mimePart->_body = ConvertUtils::base64WithLinebreak($bbody);
         $this->List->Add(new Attachment($mimePart));
         return true;
     }
     return false;
 }