Saves the email into a file
Note: If your server does not have alot of RAM, this may break

@param string $file
@param integer $id
@param string $part
@return bool true on success
@throws ImapClientException
517809
public function saveEmail($file = null, $id = null, $part = null)
     {
         // Null checks
         if($file === null)
         {
             throw new ImapClientException('File must be specified for saveEmail()');
         }
         if($id === null)
         {
             throw new ImapClientException('Email id must be specified for saveEmail()');
         }
         if($part === null)
         {
             $parts = false;
         }
         else {
             $parts = true;
         }
         // Is type checks
         if(!is_string($file))
         {
             throw new ImapClientException('File must be a string for saveEmail()');
         }
         if(!is_int($id))
         {
             throw new ImapClientException('$id must be a integer for saveEmail()');
         }
         $saveFile = fopen($file,'w');
         if($parts)
         {
             $ret = imap_savebody($this->imap, $saveFile, $id, $part);
         }
         else {
	         $ret = imap_savebody($this->imap, $saveFile, $id);
         }
         fclose($saveFile);
         
         return $ret;
     }
1014915
public Future<Boolean> sendEmail(EmailBody body, String to, String title, FilePart[] fileParts,
                                     JMailCallback callback) {
        if (StringUtils.isEmpty(to) || (body == null && fileParts == null)) {
            logger.debug("邮件没有设置接收人或者没有正文");
            execCallback(false, body, to, title, fileParts, null, this, callback);
            return ERROR;
        }

        EmailTask task = new EmailTask(body, to, title, fileParts, callback);
        return executor.submit(task);
    }
1054379
private static function persistTransactionPart($transactionPart, $transaction_id) {
        $transactionPart->transaction_id = $transaction_id;

        TransactionPersistance::setAccountBalance($transactionPart->account_id, $transactionPart->accountSide, $transactionPart->value);

        if (!$transactionPart->save(false)) {
            throw new Exception("TransactionPart could not be saved. Data: " . print_r($transactionPart->attributes,true));
        }
    }
208411
private function examinePart(&$email, $part)
    {
        //echo '<br />'.$part->part_id.' '.$part->type.' '.$part->dparameters[0]->value;
        //get subtype JPEG, WAV, HTML, PLAIN, etc
        $subtype = \strtolower($part->subtype);

        //get encoding 0 = 7bit, 1= 8bit, 2=binary, 3=base64, 4=quoted prinatble, 5=other
        $encoding = $part->encoding;

        switch ($subtype) {

            case 'plain':
                if (empty($email->body)) {
                    $email->body_encoding = $encoding;
                    $email->body = imap_fetchbody($this->inbox, $email->index, $part->part_id);
                }
                break;

            case 'html':
                $email->body_HTML = imap_fetchbody($this->inbox, $email->index, $part->part_id);
                break;

            case 'applefile':
            case 'gif':
            case 'png':
            case 'jpg':
            case 'jpeg':
            case 'wav':
            case 'mp3':
            case 'mp4':
            case 'flv':

                if ($part->type == 5) {
                    $attachment = new Email_Attachment();
                    $attachment->sizeK = $part->bytes / 1000;
                    $attachment->subtype = $subtype;
                    $attachment->type = $part->type;
                    $attachment->name = $part->dparameters[0]->value;
                    //change jpeg into jpg
                    $attachment->name = \str_ireplace('jpeg', 'jpg', $attachment->name);
                    $attachment->extension = \strtolower(end(explode(".", $attachment->name)));

                    $attachment->contents = \imap_fetchbody($this->inbox, $email->index, $part->part_id);

                    //decode base64 contents
                    if ($part->encoding == 3) {
                        $attachment->contents = \imap_base64($attachment->contents);
                    }

                    $attachment->encoding = $part->encoding;
                    $email->attachments[] = $attachment;
                }
        }
    }
777274
public function write($id , $data) {
    $crypto = $this->psl['crypt/crypto'];
    $store  = $this->psl['store'];

    /* Encrypt session. */
    try {
      $crypto->_algo = $this->cryptAlgo;
      $crypto->_mode = $this->cryptMode;
      $encrypted = $crypto->encrypt($data, $this->secret);

      /* Destroy old session. */
      if($this->newID != $this->currID) {
        $this->destroy($this->currID);
      }

      /* Write new session, with new ID. */
      return $store->write('session', $this->newID, $encrypted);
    } catch (\phpSec\Exception $e) {
      return false;
    }
  }
338545
public function save($id, $data)
    {
        $id = $this->uniqId + '-' + $id;
        if (!$this->apcIsEnabled()) {
            return false;
        }

        if (!$this->contains($id)) {
            if ($this->debug) {
                $this->cache->save($id, $data, 100);
            } else {
                $this->cache->save($id, $data);
            }

            return true;
        }

        return false;
    }
777018
protected function isEnvelopedEmail(Part $part)
    {
        if (!$this->hasHeader($part, 'Content-Type')) {
            return false;
        }

        return $this->getContentType($part)->getType() == 'message/rfc822';
    }
953325
public function setHeaderText($id, $text)
    {
        $this->_data[Horde_Imap_Client::FETCH_HEADERTEXT][$id] = $this->_setMixed($text);
    }
1300354
public function write($file, $content, $type='sandbox')
	{
		$url = 'https://api-content.dropbox.com/1/files_put/';
		$result = $this->doOAuthCall($url,'PUT',null,$type,$file,$content);
		$result_body = json_decode($result['body'],true);
		if (!array_key_exists('error', $result_body)) {
			return $result_body;
		} else {
			trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
			return false;
		}
	}
1176767
public static function createSession(int $id, string $name, string $image, string $email)
    {
        // Creates the user session with the user datas
        $_SESSION['user'] = [
            'id'    => $id,
            'name'  => $name,
            'image' => $image,
            'email' => $email
        ];
    }
790836
public function upload($id, array $files)
    {
        foreach ($files as $file) {
            if ($file instanceof FileEntity) {
                foreach ($this->dimensions as $index => $dimension) {

                    $width = (int) $dimension[0];
                    $height = (int) $dimension[1];

                    $destination = $this->makeDestination($id, $width, $height);

                    // Ensure that destination actually exists
                    if (!is_dir($destination)) {
                        mkdir($destination, 0777, true);
                    }

                    $to = sprintf('%s/%s', $destination, $file->getUniqueName());

                    $imageProcessor = new ImageProcessor($file->getTmpName());
                    $imageProcessor->thumb($width, $height);

                    // This might fail sometimes
                    $imageProcessor->save($to, $this->quality);
                }
            }
        }

        return true;
    }
1170729
public function save($file, $content)
    {
        $dir = dirname($file);

        if (!is_dir($dir)) {
            mkdir($dir, 0777);
        }

        if (file_put_contents($file, $content)) {
            chmod($file, 0777);

            return true;
        } else {
            $message = "Cannot open cache file for writing: ";
            //			if (!Nip_Staging::instance()->isPublic()) {
            //				$message .= " [ ".$this->cache_file." ] ";
            //			}
            die($message);
        }
    }
317373
public function save($id, array $data)
    {
        if(!empty($id) && (is_string($id) || is_numeric($id))) {
            $this->setFile($id);
            if ($this->file) {
                if (file_exists($this->file)) {
                    $this->update($id, $data);
                } else {
                    $this->add($id, $data);
                }
            }
        }
    }
1147100
public function addPart(PartInterface $part, $name = null)
    {
        if ($name == null) {
            $name = $part->getName();
        }
        $this->parts[$name] = $part;
    }
372994
private function failsHeaderFor(MessagePart $part, $type, $name, $header)
    {
        $headerValue = null;
        
        static $map = [
            'content-type' => 'getContentType',
            'content-disposition' => 'getContentDisposition',
            'content-transfer-encoding' => 'getContentTransferEncoding',
            'content-id' => 'getContentId'
        ];
        $lower = strtolower($name);
        if (isset($map[$lower])) {
            $headerValue = call_user_func([$part, $map[$lower]]);
        } elseif (!($part instanceof MimePart)) {
            return ($type === static::FILTER_INCLUDE);
        } else {
            $headerValue = $part->getHeaderValue($name);
        }
        
        return (($type === static::FILTER_EXCLUDE && strcasecmp($headerValue, $header) === 0)
            || ($type === static::FILTER_INCLUDE && strcasecmp($headerValue, $header) !== 0));
    }
1018782
public function write($id, $data)
    {
        // Only store session to disk if data exists or session already
        // existed before (in last case we always want to touch the file
        // to prevent early garbage collection)
        // Note: This logic can be overwritten by the force flag
        if ($data
            || $this->exists
            || $this->force
        ) {
            $file = $this->getPathForSessionId($id);
            file_put_contents($file, $data);
            chmod($file, 0600);
            $this->exists = true;
        }

        return true;
    }
708852
public OkRequest<T> part(final String name, final String filename,
                             final String contentType, final InputStream part) throws IOException {

        try {
            startPart();
            writePartHeader(name, filename, contentType);
            copy(part, mOutput);
        } catch (IOException ex) {
            throw ex;
        } catch (Exception ex) {
            VolleyLog.e(ex, "error on part");
        }


        return this;
    }