本文整理汇总了PHP中Tinebase_Helper::convertToMegabytes方法的典型用法代码示例。如果您正苦于以下问题:PHP Tinebase_Helper::convertToMegabytes方法的具体用法?PHP Tinebase_Helper::convertToMegabytes怎么用?PHP Tinebase_Helper::convertToMegabytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tinebase_Helper
的用法示例。
在下文中一共展示了Tinebase_Helper::convertToMegabytes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _ldap2User
/**
* Returns a user object with raw data from ldap
*
* @param array $_userData
* @param string $_accountClass
* @return Tinebase_Model_EmailUser
*
* @todo add generic function for this in Tinebase_User_Ldap or Tinebase_Ldap?
*/
protected function _ldap2User(Tinebase_Model_User $_user, array &$_ldapEntry)
{
#if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_ldapEntry, true));
$accountArray = $this->_defaults;
if ($this instanceof Tinebase_EmailUser_Smtp_Interface) {
$accountArray = array_merge($accountArray, array('emailForwardOnly' => false, 'emailAliases' => array(), 'emailForwards' => array()));
}
foreach ($_ldapEntry as $key => $value) {
if (is_int($key)) {
continue;
}
$keyMapping = array_search($key, $this->_propertyMapping);
if ($keyMapping !== FALSE) {
switch ($keyMapping) {
case 'emailMailQuota':
// convert to megabytes
$accountArray[$keyMapping] = Tinebase_Helper::convertToMegabytes($value[0]);
break;
case 'emailAliases':
case 'emailForwards':
$accountArray[$keyMapping] = $value;
break;
case 'emailForwardOnly':
$accountArray[$keyMapping] = strtolower($value[0]) == 'forwardonly' ? true : false;
break;
default:
$accountArray[$keyMapping] = $value[0];
break;
}
}
}
return new Tinebase_Model_EmailUser($accountArray, true);
}
示例2: _addAttachments
/**
* add attachments to mail
*
* @param Tinebase_Mail $_mail
* @param Felamimail_Model_Message $_message
* @throws Felamimail_Exception_IMAP
*/
protected function _addAttachments(Tinebase_Mail $_mail, Felamimail_Model_Message $_message)
{
if (!isset($_message->attachments) || empty($_message->attachments)) {
return;
}
$maxAttachmentSize = $this->_getMaxAttachmentSize();
$size = 0;
$tempFileBackend = Tinebase_TempFile::getInstance();
foreach ($_message->attachments as $attachment) {
if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Adding attachment: ' . (is_object($attachment) ? print_r($attachment->toArray(), TRUE) : print_r($attachment, TRUE)));
}
if (isset($attachment['type']) && $attachment['type'] == Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822 && $_message->original_id instanceof Felamimail_Model_Message) {
$part = $this->getMessagePart($_message->original_id, $_message->original_part_id ? $_message->original_part_id : NULL);
$part->decodeContent();
$name = $attachment['name'] . '.eml';
$type = $attachment['type'];
if (!empty($attachment['size'])) {
$size += $attachment['size'];
}
} else {
$tempFile = $attachment instanceof Tinebase_Model_TempFile ? $attachment : (isset($attachment['tempFile']) || array_key_exists('tempFile', $attachment) ? $tempFileBackend->get($attachment['tempFile']['id']) : NULL);
if ($tempFile === NULL) {
continue;
}
if (!$tempFile->path) {
Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Could not find attachment.');
continue;
}
// get contents from uploaded file
$stream = fopen($tempFile->path, 'r');
$part = new Zend_Mime_Part($stream);
// RFC822 attachments are not encoded, set all others to ENCODING_BASE64
$part->encoding = $tempFile->type == Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822 ? null : Zend_Mime::ENCODING_BASE64;
$name = $tempFile->name;
$type = $tempFile->type;
if (!empty($tempFile->size)) {
$size += $tempFile->size;
}
}
$part->setTypeAndDispositionForAttachment($type, $name);
if ($size > $maxAttachmentSize) {
if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Current attachment size: ' . Tinebase_Helper::convertToMegabytes($size) . ' MB / allowed size: ' . Tinebase_Helper::convertToMegabytes($maxAttachmentSize) . ' MB');
}
throw new Felamimail_Exception_IMAP('Maximum attachment size exceeded. Please remove one or more attachments.');
}
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding attachment ' . $part->type);
}
$_mail->addAttachment($part);
}
}
示例3: _rawDataToRecord
/**
* converts raw data from adapter into a single record / do mapping
*
* @param array $_data
* @return Tinebase_Model_EmailUser
*/
protected function _rawDataToRecord(array $_rawdata)
{
$data = array();
foreach ($_rawdata as $key => $value) {
$keyMapping = array_search($key, $this->_propertyMapping);
if ($keyMapping !== FALSE) {
switch ($keyMapping) {
case 'emailPassword':
// do nothing
break;
case 'emailMailQuota':
case 'emailMailSize':
case 'emailSieveQuota':
case 'emailSieveSize':
$data[$keyMapping] = Tinebase_Helper::convertToMegabytes($value);
break;
default:
$data[$keyMapping] = $value;
break;
}
}
}
return new Tinebase_Model_EmailUser($data, true);
}
示例4: _getEventAttachments
/**
* get event attachments
*
* @param Calendar_Model_Event $_event
* @return array of Zend_Mime_Part
*/
protected function _getEventAttachments($_event)
{
$attachments = array();
foreach ($_event->attachments as $attachment) {
if ($attachment->size < self::INVITATION_ATTACHMENT_MAX_FILESIZE) {
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Adding attachment " . $attachment->name . ' to invitation mail');
}
$path = Tinebase_Model_Tree_Node_Path::STREAMWRAPPERPREFIX . Tinebase_FileSystem_RecordAttachments::getInstance()->getRecordAttachmentPath($_event) . '/' . $attachment->name;
$handle = fopen($path, 'r');
$stream = fopen("php://temp", 'r+');
stream_copy_to_stream($handle, $stream);
rewind($stream);
$part = new Zend_Mime_Part($stream);
$part->encoding = Zend_Mime::ENCODING_BASE64;
// ?
$part->filename = $attachment->name;
$part->setTypeAndDispositionForAttachment($attachment->contenttype, $attachment->name);
fclose($handle);
$attachments[] = $part;
} else {
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Not adding attachment " . $attachment->name . ' to invitation mail (size: ' . Tinebase_Helper::convertToMegabytes($attachment - size) . ')');
}
}
}
return $attachments;
}
示例5: _addAttachments
/**
* add attachments to mail
*
* @param Tinebase_Mail $_mail
* @param Felamimail_Model_Message $_message
* @throws Felamimail_Exception_IMAP
*/
protected function _addAttachments(Tinebase_Mail $_mail, Felamimail_Model_Message $_message)
{
if (!isset($_message->attachments) || empty($_message->attachments)) {
return;
}
$maxAttachmentSize = $this->_getMaxAttachmentSize();
$totalSize = 0;
foreach ($_message->attachments as $attachment) {
if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Adding attachment: ' . (is_object($attachment) ? print_r($attachment->toArray(), TRUE) : print_r($attachment, TRUE)));
}
if (isset($attachment['type']) && $attachment['type'] == Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822 && $_message->original_id instanceof Felamimail_Model_Message) {
$part = $this->_getRfc822Attachment($attachment, $_message);
} else {
if ($attachment instanceof Tinebase_Model_TempFile || isset($attachment['tempFile'])) {
$part = $this->_getTempFileAttachment($attachment);
} else {
$part = $this->_getMessagePartAttachment($attachment);
}
}
if (!$part || empty($attachment['type'])) {
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Skipping attachment ' . print_r($attachment, true));
}
continue;
}
$part->setTypeAndDispositionForAttachment($attachment['type'], $attachment['name']);
if (!empty($attachment['size'])) {
$totalSize += $attachment['size'];
}
if ($totalSize > $maxAttachmentSize) {
if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Current attachment size: ' . Tinebase_Helper::convertToMegabytes($totalSize) . ' MB / allowed size: ' . Tinebase_Helper::convertToMegabytes($maxAttachmentSize) . ' MB');
}
throw new Felamimail_Exception_IMAP('Maximum attachment size exceeded. Please remove one or more attachments.');
}
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding attachment ' . $part->type);
}
$_mail->addAttachment($part);
}
}