/** * @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 ''; }
/** * @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]); } }
/** * @param string $nputCharset */ function ReparseAllHeader($inputCharset) { for ($i = 0, $c = $this->Headers->Count(); $i < $c; $i++) { $header =& $this->Headers->Get($i); if (!ConvertUtils::IsLatin($header->Value)) { $header->Value = ConvertUtils::ConvertEncoding($header->Value, $inputCharset, $GLOBALS[MailOutputCharset]); $header->IsParsed = true; } } }
/** * @param FolderCollection $_folders * @param XmlDomNode $_nodeTree * @param MailProcessor $_processor */ function GetFoldersTreeXml(&$_folders, &$_nodeTree, &$_processor) { for ($_i = 0, $_count = $_folders->Count(); $_i < $_count; $_i++) { $_folder =& $_folders->Get($_i); $_folderNode = new XmlDomNode('folder'); $_folderNode->AppendAttribute('id', $_folder->IdDb); $_folderNode->AppendAttribute('id_parent', $_folder->IdParent); $_folderNode->AppendAttribute('type', $_folder->Type); $_folderNode->AppendAttribute('sync_type', $_folder->SyncType); $_folderNode->AppendAttribute('hide', (int) $_folder->Hide); $_folderNode->AppendAttribute('fld_order', (int) $_folder->FolderOrder); if ($_folder->SyncType == FOLDERSYNC_DirectMode) { $_processor->GetFolderMessageCount($_folder); } $_folderNode->AppendAttribute('count', $_folder->MessageCount); $_folderNode->AppendAttribute('count_new', $_folder->UnreadMessageCount); $_folderNode->AppendAttribute('size', $_folder->Size); if (ConvertUtils::IsLatin($_folder->Name)) { $_folderNode->AppendChild(new XmlDomNode('name', ConvertUtils::ConvertEncoding($_folder->Name, CPAGE_UTF7_Imap, CPAGE_UTF8), true)); } else { $_folderNode->AppendChild(new XmlDomNode('name', ConvertUtils::ConvertEncoding($_folder->Name, $_processor->_account->DefaultIncCharset, CPAGE_UTF8), true)); } $_folderNode->AppendChild(new XmlDomNode('full_name', $_folder->FullName, true)); if ($_folder->SubFolders != null && $_folder->SubFolders->Count() > 0) { $_foldersNode = new XmlDomNode('folders'); CXmlProcessing::GetFoldersTreeXml($_folder->SubFolders, $_foldersNode, $_processor); $_folderNode->AppendChild($_foldersNode); unset($_foldersNode); } $_nodeTree->AppendChild($_folderNode); unset($_folderNode, $_folder); } }
function GetFolderFullName($account) { return ConvertUtils::IsLatin($this->FullName) ? ConvertUtils::ConvertEncoding($this->FullName, CPAGE_UTF7_Imap, $account->GetUserCharset()) : ConvertUtils::ConvertEncoding($this->FullName, $account->DefaultIncCharset, $account->GetUserCharset()); }
/** * @param FolderCollection $folderCollection * @return String */ function CreateHtmlFolderTree($folderCollection) { $out = ''; for ($i = 0, $c = $folderCollection->Count(); $i < $c; $i++) { $folder =& $folderCollection->Get($i); $foldername = ''; if (ConvertUtils::IsLatin($folder->Name)) { $foldername = ConvertUtils::ConvertEncoding($folder->Name, CPAGE_UTF7_Imap, $this->_pagebuilder->_proc->account->GetUserCharset()); } else { $foldername = ConvertUtils::ConvertEncoding($folder->Name, $this->_pagebuilder->_proc->account->DefaultIncCharset, $this->_pagebuilder->_proc->account->GetUserCharset()); } $isselect = ''; if ($this->_pagebuilder->_proc->currentFolder && $this->_pagebuilder->_proc->currentFolder->IdDb == $folder->IdDb) { $isselect = 'class="wm_select_folder"'; } if (!$folder->Hide) { $out .= '<div style="padding-left: ' . $folder->Level * 8 . 'px;" ' . $isselect . '>'; $out .= '<a href="?' . FOLDER_ID . '=' . $folder->IdDb . '">'; $out .= '<img src="./skins/' . $this->_pagebuilder->SkinName() . '/folders/' . $this->GetFolderImg($folder) . '" />'; switch ($folder->Type) { default: case FOLDERTYPE_Custom: $out .= ConvertUtils::WMHtmlSpecialChars($foldername); break; case FOLDERTYPE_Inbox: $out .= FolderInbox; break; case FOLDERTYPE_Drafts: $out .= FolderDrafts; break; case FOLDERTYPE_SentItems: $out .= FolderSentItems; break; case FOLDERTYPE_Trash: $out .= FolderTrash; break; } if ($folder->SyncType == FOLDERSYNC_DirectMode) { $out .= ' <span id="cnt_' . $folder->IdDb . '" class="wm_hide"></span></a>'; $out .= ' <span title="' . ConvertUtils::AttributeQuote(DirectAccessTitle) . '" class="wm_folder_direct_mode"> ' . DirectAccess . ' </span>'; } else { $out .= $folder->UnreadMessageCount > 0 ? ' <span id="cnt_' . $folder->IdDb . '">(' . $folder->UnreadMessageCount . ')</span></a>' : ' <span id="cnt_' . $folder->IdDb . '"></span></a>'; } $out .= '</div>'; if ($folder->SubFolders != null && $folder->SubFolders->Count() > 0) { $out .= $this->CreateHtmlFolderTree($folder->SubFolders); } } } return $out; }
/** * @param Folder $folders * @param DbStorage $dbStorage * @param int $lastIdMsg * @return bool */ function _synchronizeFolderWithOpenDbConnection(&$folder, &$dbStorage, $lastIdMsg) { $result = true; if ($folder->SyncType == FOLDERSYNC_DontSync || $folder->SyncType == FOLDERSYNC_DirectMode || $folder->Hide) { return true; } if (!$this->_imapMail->examine_mailbox($folder->FullName)) { return false; } //Get uid, flags and size from imap Server $paramsMessages = $this->_imapMail->getParamsMessages(); $imapFlags = array(); $imapUids = array(); $imapSizes = array(); $dbUids = array(); $imapUidFlags = array(); if (!is_array($paramsMessages)) { return false; } foreach ($paramsMessages as $key => $value) { $imapFlags[$key] = $value["flag"]; $imapUids[$key] = $value["uid"]; $imapSizes[$key] = $value["size"]; $imapUidFlags[$value["uid"]] = $value["flag"]; $imapUidSizes[$value["uid"]] = $value["size"]; } $dbUidsIdMsgsFlags =& $dbStorage->SelectIdMsgAndUidByIdMsgDesc($folder); foreach ($dbUidsIdMsgsFlags as $value) { $dbUidsFlag[$value[1]] = $value[2]; $dbUids[] = $value[1]; } //Array need added to DB $newUids = array_diff($imapUids, $dbUids); //Array delete from DB $uidsToDelete = array_diff($dbUids, $imapUids); //Intersect uids $currentUids = array_intersect($imapUids, $dbUids); if ($folder->SyncType == FOLDERSYNC_AllHeadersOnly || $folder->SyncType == FOLDERSYNC_AllEntireMessages) { //Update messages whith different flags foreach ($currentUids as $currentUid) { $flagBD = $dbUidsFlag[$currentUid]; $flagImap = $this->getIntFlags($imapUidFlags[$currentUid]); if ($flagBD != $flagImap) { $dbStorage->UpdateMessageFlags(array($currentUid), true, $folder, $flagImap, $this->Account); } } } if ($this->DownloadedMessagesHandler != null) { if (ConvertUtils::IsLatin($folder->Name)) { $foldername = ConvertUtils::ConvertEncoding($folder->Name, CPAGE_UTF7_Imap, $this->Account->GetUserCharset()); } else { $foldername = ConvertUtils::ConvertEncoding($folder->Name, $this->Account->DefaultIncCharset, $this->Account->GetUserCharset()); } ShowDownloadedMessageNumber($foldername, count($newUids)); ShowDownloadedMessageNumber(); } //Delete from DB if (count($uidsToDelete) > 0 && ($folder->SyncType == FOLDERSYNC_AllHeadersOnly || $folder->SyncType == FOLDERSYNC_AllEntireMessages)) { //$result &= $dbStorage->DeleteMessages($uidsToDelete, true, $folder); $result &= $dbStorage->SetMessagesFlags($uidsToDelete, true, $folder, MESSAGEFLAGS_Deleted, ACTION_Set); } $result &= $dbStorage->UpdateMailboxSize(); $maxEnvelopesPerSession = 1; //Get size all messages in DB $mailBoxesSize = $dbStorage->SelectMailboxesSize(); $syncCycles = ceil(count($newUids) / $maxEnvelopesPerSession); for ($i = 0; $i < $syncCycles; $i++) { $mailBoxesSize += $imapSizes[$i + 1]; if ($this->_settings->EnableMailboxSizeLimit && $this->Account->MailboxLimit < $mailBoxesSize) { $result = false; setGlobalError(ErrorGetMailLimit); break; } $listPartToDownload = $i != $syncCycles - 1 ? array_slice($newUids, $i * $maxEnvelopesPerSession, $maxEnvelopesPerSession) : array_slice($newUids, $i * $maxEnvelopesPerSession); //Synchronize if ($folder->SyncType == FOLDERSYNC_NewEntireMessages || $folder->SyncType == FOLDERSYNC_AllEntireMessages) { $mailMessageCollection =& $this->LoadMessages($listPartToDownload, true, $folder, $imapUids, $imapUidFlags, $imapUidSizes); } elseif ($folder->SyncType == FOLDERSYNC_NewHeadersOnly || $folder->SyncType == FOLDERSYNC_AllHeadersOnly) { $mailMessageCollection =& $this->_loadMessageHeaders($listPartToDownload, $imapUids, $imapUidFlags, $imapUidSizes); } //Write to DB if ($mailMessageCollection != null && $mailMessageCollection->Count() > 0) { if (!$this->ApplyFilters($mailMessageCollection, $dbStorage, $folder)) { $result = false; break; } } } $result &= $dbStorage->UpdateMailboxSize(); return $result; }
function CreateSelectFolderTreeForFilters(&$folders, $id = -1) { $out = ''; for ($i = 0, $count = $folders->Count(); $i < $count; $i++) { $folder =& $folders->Get($i); if (ConvertUtils::IsLatin($folder->Name)) { $foldername = ConvertUtils::ConvertEncoding($folder->Name, CPAGE_UTF7_Imap, $this->setaccount->_pagebuilder->_proc->account->GetUserCharset()); } else { $foldername = ConvertUtils::ConvertEncoding($folder->Name, $this->setaccount->_pagebuilder->_proc->account->DefaultIncCharset, $this->setaccount->_pagebuilder->_proc->account->GetUserCharset()); } $out .= $id == $folder->IdDb ? '<option value="' . $folder->IdDb . '" selected="selected">' . str_repeat(' ', $folder->Level * 3) . $foldername . '</option>' . "\r\n" : '<option value="' . $folder->IdDb . '">' . str_repeat(' ', $folder->Level * 3) . $foldername . '</option>'; if ($folder->SubFolders != null && $folder->SubFolders->Count() > 0) { $out .= $this->CreateSelectFolderTreeForFilters($folder->SubFolders, $id); } } return $out; }
/** * @param string $str * @param string $toCharset * @return array */ function EncodeString($str, $toCharset) { $outarray = array(); /* $factor = (MIMEConst_DefaultQB == MIMEConst_QuotedPrintableShort) ? 0.35 : 0.7; */ $outarray = strtolower($toCharset) == 'utf-8' ? ConvertUtils::SmartChunk($str, MIMEConst_DefaultQB, $toCharset, true) : ConvertUtils::SmartChunk($str, MIMEConst_DefaultQB, $toCharset, false); if (!ConvertUtils::IsLatin($str)) { for ($i = 0, $c = count($outarray); $i < $c; $i++) { if (MIMEConst_DefaultQB == MIMEConst_QuotedPrintableShort) { $outarray[$i] = '=?' . strtolower($toCharset) . '?Q?' . str_replace('?', '=3F', str_replace(' ', '_', str_replace('_', '=5F', ConvertUtils::quotedPrintableWithLinebreak($outarray[$i], true)))) . '?='; } else { if (MIMEConst_DefaultQB == MIMEConst_Base64Short) { $outarray[$i] = '=?' . strtolower($toCharset) . '?B?' . base64_encode($outarray[$i]) . '?='; } } } } return $outarray; }
/** * @param FolderCollection $folderCollection * @return String */ function CreateFolderTree($folderCollection) { $out = ''; for ($i = 0, $c = $folderCollection->Count(); $i < $c; $i++) { $folder =& $folderCollection->Get($i); if ($folder->Hide) { continue; } if ($folder->SyncType == FOLDERSYNC_DirectMode && $this->_pagebuilder->_proc->account->MailProtocol == MAILPROTOCOL_POP3) { continue; } $foldername = ''; if (ConvertUtils::IsLatin($folder->Name)) { $foldername = ConvertUtils::ConvertEncoding($folder->Name, CPAGE_UTF7_Imap, $this->_pagebuilder->_proc->account->GetUserCharset()); } else { $foldername = ConvertUtils::ConvertEncoding($folder->Name, $this->_pagebuilder->_proc->account->DefaultIncCharset, $this->_pagebuilder->_proc->account->GetUserCharset()); } $out .= '<div onclick="MoveToFolder(\'' . $folder->IdDb . '\');" class="wm_menu_item" onmouseover="this.className=\'wm_menu_item_over\';" onmouseout="this.className=\'wm_menu_item\';">' . str_repeat(' ', (int) $folder->Level * 4); switch ($folder->Type) { default: case FOLDERTYPE_Custom: $out .= ConvertUtils::WMHtmlSpecialChars($foldername); break; case FOLDERTYPE_Inbox: $out .= FolderInbox; break; case FOLDERTYPE_Drafts: $out .= FolderDrafts; break; case FOLDERTYPE_SentItems: $out .= FolderSentItems; break; case FOLDERTYPE_Trash: $out .= FolderTrash; break; } $out .= '</div>'; if ($folder->SubFolders != null && $folder->SubFolders->Count() > 0) { $out .= $this->CreateFolderTree($folder->SubFolders); } } return $out; }