function rc_wordwrap($string, $width = 75, $break = "\n", $cut = false, $charset = null) { return rcube_mime::wordwrap($string, $width, $break, $cut, $charset); }
/** * Handler for message signing * * @param Mail_mime Original message * @param int Encryption mode * * @return enigma_error On error returns error object */ function sign_message(&$message, $mode = null) { $mime = new enigma_mime_message($message, enigma_mime_message::PGP_SIGNED); $from = $mime->getFromAddress(); // find private key $key = $this->find_key($from, true); if (empty($key)) { return new enigma_error(enigma_error::KEYNOTFOUND); } // check if we have password for this key $passwords = $this->get_passwords(); $pass = $passwords[$key->id]; if ($pass === null) { // ask for password $error = array('missing' => array($key->id => $key->name)); return new enigma_error(enigma_error::BADPASS, '', $error); } $key->password = $pass; // select mode switch ($mode) { case self::SIGN_MODE_BODY: $pgp_mode = Crypt_GPG::SIGN_MODE_CLEAR; break; case self::SIGN_MODE_MIME: $pgp_mode = Crypt_GPG::SIGN_MODE_DETACHED; break; /* case self::SIGN_MODE_SEPARATE: $pgp_mode = Crypt_GPG::SIGN_MODE_NORMAL; break; */ /* case self::SIGN_MODE_SEPARATE: $pgp_mode = Crypt_GPG::SIGN_MODE_NORMAL; break; */ default: if ($mime->isMultipart()) { $pgp_mode = Crypt_GPG::SIGN_MODE_DETACHED; } else { $pgp_mode = Crypt_GPG::SIGN_MODE_CLEAR; } } // get message body if ($pgp_mode == Crypt_GPG::SIGN_MODE_CLEAR) { // in this mode we'll replace text part // with the one containing signature $body = $message->getTXTBody(); $text_charset = $message->getParam('text_charset'); $line_length = $this->rc->config->get('line_length', 72); // We can't use format=flowed for signed messages if (strpos($text_charset, 'format=flowed')) { list($charset, $params) = explode(';', $text_charset); $body = rcube_mime::unfold_flowed($body); $body = rcube_mime::wordwrap($body, $line_length, "\r\n", false, $charset); $text_charset = str_replace(";\r\n format=flowed", '', $text_charset); } } else { // here we'll build PGP/MIME message $body = $mime->getOrigBody(); } // sign the body $result = $this->pgp_sign($body, $key, $pgp_mode); if ($result !== true) { if ($result->getCode() == enigma_error::BADPASS) { // ask for password $error = array('bad' => array($key->id => $key->name)); return new enigma_error(enigma_error::BADPASS, '', $error); } return $result; } // replace message body if ($pgp_mode == Crypt_GPG::SIGN_MODE_CLEAR) { $message->setTXTBody($body); $message->setParam('text_charset', $text_charset); } else { $mime->addPGPSignature($body); $message = $mime; } }
function rcmail_wrap_and_quote($text, $length = 72) { // Rebuild the message body with a maximum of $max chars, while keeping quoted message. $max = max(75, $length + 8); $lines = preg_split('/\\r?\\n/', trim($text)); $out = ''; foreach ($lines as $line) { // don't wrap already quoted lines if ($line[0] == '>') { $line = '>' . rtrim($line); } else { if (mb_strlen($line) > $max) { $newline = ''; foreach (explode("\n", rcube_mime::wordwrap($line, $length - 2)) as $l) { if (strlen($l)) { $newline .= '> ' . $l . "\n"; } else { $newline .= ">\n"; } } $line = rtrim($newline); } else { $line = '> ' . $line; } } // Append the line $out .= $line . "\n"; } return rtrim($out, "\n"); }
function rc_wordwrap($string, $width = 75, $break = "\n", $cut = false, $charset = null) { _deprecation_warning(__FUNCTION__); return rcube_mime::wordwrap($string, $width, $break, $cut, $charset); }