/**
  * Given array of MIME parts in raw string, this function converts them into MIME
  * representation. 
  * 
  * @param array $bodyPartContents The MIME body parts.
  * 
  * @return array Returns array with two elements 'headers' and 'body' which
  * represents the MIME message.
  */
 public function encodeMimeMultipart($bodyPartContents)
 {
     $count = count($bodyPartContents);
     $mimeType = Resources::MULTIPART_MIXED_TYPE;
     $batchGuid = strtolower(trim(com_create_guid(), '{}'));
     $batchId = sprintf('batch_%s', $batchGuid);
     $contentType1 = array('content_type' => "{$mimeType}");
     $changeSetGuid = strtolower(trim(com_create_guid(), '{}'));
     $changeSetId = sprintf('changeset_%s', $changeSetGuid);
     $contentType2 = array('content_type' => "{$mimeType}; boundary={$changeSetId}");
     $options = array('encoding' => 'binary', 'content_type' => Resources::HTTP_TYPE);
     // Create changeset MIME part
     $changeSet = new \Mail_mimePart();
     for ($i = 0; $i < $count; $i++) {
         $changeSet->addSubpart($bodyPartContents[$i], $options);
     }
     // Encode the changeset MIME part
     $changeSetEncoded = $changeSet->encode($changeSetId);
     // Create the batch MIME part
     $batch = new \Mail_mimePart(Resources::EMPTY_STRING, $contentType1);
     // Add changeset encoded to batch MIME part
     $batch->addSubpart($changeSetEncoded['body'], $contentType2);
     // Encode batch MIME part
     $batchEncoded = $batch->encode($batchId);
     return $batchEncoded;
 }
 public function send()
 {
     $to = $this->getSetting('to', '');
     $from = $this->getSetting('from', '');
     $subject = $this->getSetting('subject', '');
     $encoding = $this->getSetting('encoding', '');
     $body = $this->getSetting('content', '');
     $error = '';
     $crlf = '';
     $params = array();
     $params['host'] = $this->getSetting('server', '');
     $params['auth'] = $this->getSetting('auth', true);
     $params['username'] = $this->getSetting('user', '');
     $params['password'] = $this->getSetting('password', '');
     $params['port'] = $this->getSetting('port', '587');
     $headers = array();
     $headers['To'] = 'To: ' . $to;
     $headers['From'] = 'From: ' . $from;
     $headers['Subject'] = $subject;
     $htmlparams = array('charset' => 'utf-8', 'content_type' => 'text/html', 'encoding' => 'quoted/printable');
     $email = new Mail_mimePart('', array('content_type' => 'multipart/alternative'));
     $htmlmime = $email->addSubPart($this->getTemplate(), $htmlparams);
     $final = $email->encode();
     $final['headers'] = array_merge($final['headers'], $headers);
     $smtp = Mail::factory('smtp', $params);
     $mail = $smtp->send($to, $final['headers'], $final['body']);
     if (PEAR::isError($mail)) {
         $error = $mail->getMessage();
     }
     return $error;
 }
Example #3
0
 public function sendTextMail(PrmPerson $to, $Header, $Body, PrmPerson $ReplyTo = null)
 {
     $headers['To'] = $to->getForMailUser();
     $headers['From'] = $this->_From;
     $headers['Return-Path'] = $this->_From;
     if ($ReplyTo != null) {
         $headers['Reply-To'] = $ReplyTo->getForMailUser();
     }
     $headers['Subject'] = $Header;
     $headers['Errors-To'] = '<<a href="mailto:errors@example.com">errors@example.com</a>>';
     $headers['MIME-Version'] = '1.0';
     $textparams = array('charset' => 'utf-8', 'content_type' => 'text/plain', 'encoding' => 'quoted/printable');
     $email = new Mail_mimePart('', array('content_type' => 'multipart/alternative'));
     $textmime = $email->addSubPart($Body, $textparams);
     $final = $email->encode();
     $final['headers'] = array_merge($final['headers'], $headers);
     $smtp_params = array();
     $smtp_params['host'] = $this->_Host;
     $smtp_params['port'] = $this->_Port;
     $smtp_params['auth'] = true;
     $smtp_params['username'] = $this->_UserName;
     $smtp_params['password'] = $this->_Password;
     $smtp_params['debug'] = false;
     //$smtp_params['persist'] = TRUE;
     $mail =& Mail::factory('smtp', $smtp_params);
     $status = $mail->send($to->getForMailUser(), $final['headers'], $final['body']);
     if (PEAR::isError($status)) {
         print $status->getMessage();
         exit;
         return false;
     } else {
         return true;
     }
 }
Example #4
0
 public function sendMMS($senderAddress, $addressList, $message, $attachments, $senderName, $clientCorrelator, $notifyURL, $callbackData)
 {
     $sendMMSResponse = null;
     if ($senderAddress && $addressList && ($message || $attachments)) {
         if (!is_null($this->endpoint) && property_exists($this->endpoint, 'SendSMS')) {
             $url = $this->endpoint->getSendMMSEndpoint();
         } else {
             $url = 'http://localhost:8080/oneapiserver/SendMMSService/1/messaging/outbound/{senderAddress}/requests';
         }
         $url = str_replace('{senderAddress}', urlencode($senderAddress), $url);
         $formParameters = new FormParameters();
         $formParameters->put("senderAddress", $senderAddress);
         for ($i = 0; $i < count($addressList); $i++) {
             $formParameters->put("address", $addressList[$i]);
         }
         $formParameters->put("message", $message);
         $formParameters->put("clientCorrelator", $clientCorrelator);
         $formParameters->put("notifyURL", $notifyURL);
         $formParameters->put("senderName", $senderName);
         $formParameters->put("callbackData", $callbackData);
         $params = array();
         $params['content_type'] = 'multipart/mixed';
         $requestBody = new Mail_mimePart('', $params);
         $params['content_type'] = 'application/x-www-form-urlencoded';
         //$params['encoding']     = '8bit';
         $params['disposition'] = 'form-data; name="root-fields"';
         $text = $requestBody->addSubPart($formParameters->encodeParameters(), $params);
         error_log('Processing attachments');
         if ($attachments && is_array($attachments) && count($attachments) > 0) {
             for ($i = 0; $i < count($attachments); $i++) {
                 error_log('Processing file ' . $i);
                 $file = $attachments[$i];
                 if ($file && is_array($file) && isset($file['error']) && $file['error'] == UPLOAD_ERR_OK) {
                     error_log('Have attachment name=' . $file['name'] . ' type=' . $file['type'] . ' size=' . $file['size']);
                     $params['content_type'] = $file['type'];
                     $params['encoding'] = 'base64';
                     $params['disposition'] = 'form-data; name="' . $file['name'] . '"';
                     $contents = file_get_contents($file['tmp_name']);
                     $attach =& $requestBody->addSubPart($contents, $params);
                 }
             }
         }
         $content = $requestBody->encode();
         $contentType = $content['headers']['Content-Type'];
         $data = $content['body'];
         error_log('Generated...\\n' . print_r($content, true));
         $request = new JSONRequest($url, $this->username, $this->password, 'POST', null, $contentType, $data);
         $response = $request->execute();
         if ($response->getResponseBody()) {
             $jsondata = json_decode($response->getResponseBody());
         }
         error_log("MMSSend::sendMMS response=" . print_r($response, true));
         error_log("MMSSend::sendMMS jsondata=" . print_r($jsondata, true));
         $responseInfo = $response->getResponseInfo();
         $location = $response->getLocation();
         $sendMMSResponse = new MMSSendResponse($responseInfo["http_code"], $responseInfo["content_type"], $location, $jsondata);
         error_log("MMSSend::sendMMS sendMMSResponse=" . print_r($sendMMSResponse, true));
     }
     return $sendMMSResponse;
 }
 protected function eF_mail_multipart($sender, $recipient, $subject, $textbody, $calendarbody, $onlyText = false, $bcc = false)
 {
     $hdrs = array('From' => $sender, 'Subject' => $subject, 'Date' => date("r"));
     if ($bcc) {
         //$hdrs['To'] = '';
     }
     $params = array("text_charset" => "UTF-8", "html_charset" => "UTF-8", "head_charset" => "UTF-8", "head_encoding" => "base64");
     $textparams = array('charset' => 'utf-8', 'content_type' => 'text/plain', 'encoding' => 'base64');
     $calendarparams = array('charset' => 'utf-8', 'content_type' => 'text/calendar;method=REQUEST', 'encoding' => 'base64');
     $email = new Mail_mimePart('', array('content_type' => 'multipart/alternative'));
     $textmime = $email->addSubPart($textbody, $textparams);
     $htmlmime = $email->addSubPart($calendarbody, $calendarparams);
     $final = $email->encode();
     $final['headers'] = array_merge($final['headers'], $hdrs);
     $smtp = Mail::factory('smtp', array('auth' => $GLOBALS['configuration']['smtp_auth'] ? true : false, 'host' => $GLOBALS['configuration']['smtp_host'], 'password' => $GLOBALS['configuration']['smtp_pass'], 'port' => $GLOBALS['configuration']['smtp_port'], 'username' => $GLOBALS['configuration']['smtp_user'], 'timeout' => $GLOBALS['configuration']['smtp_timeout'], 'localhost' => $_SERVER["HTTP_HOST"]));
     $result = $smtp->send($recipient, $final['headers'], $final['body']);
     return $result;
 }
Example #6
0
 function &_makeMimeMessage(&$xml, $encoding = SOAP_DEFAULT_ENCODING)
 {
     global $SOAP_options;
     if (!isset($SOAP_options['Mime'])) {
         return $this->_raiseSoapFault('Mime is not installed');
     }
     // encode any attachments
     // see http://www.w3.org/TR/SOAP-attachments
     // now we have to mime encode the message
     $params = array('content_type' => 'multipart/related; type=text/xml');
     $msg = new Mail_mimePart('', $params);
     // add the xml part
     $params['content_type'] = 'text/xml';
     $params['charset'] = $encoding;
     $params['encoding'] = 'base64';
     $msg->addSubPart($xml, $params);
     // add the attachements
     $c = count($this->__attachments);
     for ($i = 0; $i < $c; $i++) {
         $attachment =& $this->__attachments[$i];
         $msg->addSubPart($attachment['body'], $attachment);
     }
     return $msg->encode();
 }
Example #7
0
 /**
  * Encodes a header as per RFC2047
  *
  * @param string $name     The header name
  * @param string $value    The header data to encode
  * @param string $charset  Character set name
  * @param string $encoding Encoding name (base64 or quoted-printable)
  *
  * @return string          Encoded header data (without a name)
  * @access public
  * @since 1.5.3
  */
 function encodeHeader($name, $value, $charset, $encoding)
 {
     $mime_part = new Mail_mimePart();
     return $mime_part->encodeHeader($name, $value, $charset, $encoding, $this->_build_params['eol']);
 }
Example #8
0
 /**
  * gets the HTTP body for the current response.
  *
  * @param string $soapmsg The SOAP payload
  * @return string The HTTP body, which includes the SOAP payload
  * @access private
  */
 function getHTTPBody($soapmsg)
 {
     if (count($this->responseAttachments) > 0) {
         $params['content_type'] = 'multipart/related; type="text/xml"';
         $mimeMessage = new Mail_mimePart('', $params);
         unset($params);
         $params['content_type'] = 'text/xml';
         $params['encoding'] = '8bit';
         $params['charset'] = $this->soap_defencoding;
         $mimeMessage->addSubpart($soapmsg, $params);
         foreach ($this->responseAttachments as $att) {
             unset($params);
             $params['content_type'] = $att['contenttype'];
             $params['encoding'] = 'base64';
             $params['disposition'] = 'attachment';
             $params['dfilename'] = $att['filename'];
             $params['cid'] = $att['cid'];
             if ($att['data'] == '' && $att['filename'] != '') {
                 if ($fd = fopen($att['filename'], 'rb')) {
                     $data = fread($fd, filesize($att['filename']));
                     fclose($fd);
                 } else {
                     $data = '';
                 }
                 $mimeMessage->addSubpart($data, $params);
             } else {
                 $mimeMessage->addSubpart($att['data'], $params);
             }
         }
         $output = $mimeMessage->encode();
         $mimeHeaders = $output['headers'];
         foreach ($mimeHeaders as $k => $v) {
             $this->debug("MIME header {$k}: {$v}");
             if (strtolower($k) == 'content-type') {
                 // PHP header() seems to strip leading whitespace starting
                 // the second line, so force everything to one line
                 $this->mimeContentType = str_replace("\r\n", " ", $v);
             }
         }
         return $output['body'];
     }
     return parent::getHTTPBody($soapmsg);
 }
Example #9
0
File: Base.php Project: rolwi/koala
 function _makeMimeMessage($xml, $encoding = SOAP_DEFAULT_ENCODING)
 {
     if (!@(include_once 'Mail/mimePart.php')) {
         return $this->_raiseSoapFault('MIME messages are unsupported, the Mail_Mime package is not installed');
     }
     // Encode any attachments.  See http://www.w3.org/TR/SOAP-attachments
     // Now we have to mime encode the message.
     $params = array('content_type' => 'multipart/related; type="text/xml"');
     $msg = new Mail_mimePart('', $params);
     // Add the xml part.
     $params['content_type'] = 'text/xml';
     $params['charset'] = $encoding;
     $params['encoding'] = 'base64';
     $msg->addSubPart($xml, $params);
     // Add the attachements
     for ($i = 0, $c = count($this->_attachments); $i < $c; ++$i) {
         $msg->addSubPart($this->_attachments[$i]['body'], $this->_attachments[$i]);
     }
     return $msg->encode();
 }
Example #10
0
 /**
  * Add text parts to a mimepart object
  *
  * @param Mail_mimePart $email reference to the object
  * @param Mail_mimeDecode $message reference to the message
  *
  * @access private
  * @return void
  */
 private function addTextPartsMessage(&$email, &$message)
 {
     $altEmail = new Mail_mimePart('', array('content_type' => 'multipart/alternative'));
     foreach (array("plain", "html", "calendar") as $type) {
         $body = '';
         Mail_mimeDecode::getBodyRecursive($message, $type, $body);
         if (strlen($body) > 0) {
             ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->addTextPartsMessage(): The message has %s body", $type));
             $altEmail->addSubPart($body, array('content_type' => sprintf("text/%s; charset=utf-8", $type), 'encoding' => 'base64'));
         }
     }
     unset($body);
     $boundary = '=_' . md5(rand() . microtime());
     $altEmail = $altEmail->encode($boundary);
     $email->addSubPart($altEmail['body'], array('content_type' => 'multipart/alternative;' . "\n" . ' boundary="' . $boundary . '"'));
     unset($altEmail);
 }
/**
 * Creates a MIME message from a decoded MIME message, reencoding and fixing the text.
 *
 * @param array $message array returned from Mail_mimeDecode->decode
 *
 * @access public
 * @return string MIME message
 */
function build_mime_message($message)
{
    $finalEmail = new Mail_mimePart(isset($message->body) ? $message->body : "", array('headers' => $message->headers));
    if (isset($message->parts)) {
        foreach ($message->parts as $part) {
            change_charset_and_add_subparts($finalEmail, $part);
        }
    }
    $mimeHeaders = array();
    $mimeHeaders['headers'] = array();
    $is_mime = false;
    foreach ($message->headers as $key => $value) {
        switch ($key) {
            case 'content-type':
                $new_value = $message->ctype_primary . "/" . $message->ctype_secondary;
                $is_mime = strcasecmp($message->ctype_primary, 'multipart') == 0;
                if (isset($message->ctype_parameters)) {
                    foreach ($message->ctype_parameters as $ckey => $cvalue) {
                        switch ($ckey) {
                            case 'charset':
                                $new_value .= '; charset="UTF-8"';
                                break;
                            case 'boundary':
                                // Do nothing, we are encoding also the headers
                                break;
                            default:
                                $new_value .= '; ' . $ckey . '="' . $cvalue . '"';
                                break;
                        }
                    }
                }
                $mimeHeaders['content_type'] = $new_value;
                break;
            case 'content-transfer-encoding':
                if (strcasecmp($value, "base64") == 0 || strcasecmp($value, "binary") == 0) {
                    $mimeHeaders['encoding'] = "base64";
                } else {
                    $mimeHeaders['encoding'] = "8bit";
                }
                break;
            case 'content-id':
                $mimeHeaders['cid'] = $value;
                break;
            case 'content-location':
                $mimeHeaders['location'] = $value;
                break;
            case 'content-disposition':
                $mimeHeaders['disposition'] = $value;
                break;
            case 'content-description':
                $mimeHeaders['description'] = $value;
                break;
            default:
                if (is_array($value)) {
                    foreach ($value as $v) {
                        $mimeHeaders['headers'][$key] = $v;
                    }
                } else {
                    $mimeHeaders['headers'][$key] = $value;
                }
                break;
        }
    }
    $finalEmail = new Mail_mimePart(isset($message->body) ? $message->body : "", $mimeHeaders);
    unset($mimeHeaders['headers']);
    unset($mimeHeaders);
    if (isset($message->parts)) {
        foreach ($message->parts as $part) {
            change_charset_and_add_subparts($finalEmail, $part);
        }
    }
    $boundary = '=_' . md5(rand() . microtime());
    $finalEmail = $finalEmail->encode($boundary);
    $headers = "";
    $mimePart = new Mail_mimePart();
    foreach ($finalEmail['headers'] as $key => $value) {
        if (is_array($value)) {
            foreach ($values as $ikey => $ivalue) {
                $headers .= $key . ": " . $mimePart->encodeHeader($key, $ivalue, "utf-8", "base64") . "\n";
            }
        } else {
            $headers .= $key . ": " . $mimePart->encodeHeader($key, $value, "utf-8", "base64") . "\n";
        }
    }
    unset($mimePart);
    if ($is_mime) {
        $built_message = "{$headers}\nThis is a multi-part message in MIME format.\n" . $finalEmail['body'];
    } else {
        $built_message = "{$headers}\n" . $finalEmail['body'];
    }
    unset($headers);
    unset($finalEmail);
    return $built_message;
}
Example #12
0
/**
 * Add a subpart to a mimepart object.
 *
 * @param Mail_mimePart $email reference to the object
 * @param object $part message part
 *
 * @access private
 * @return void
 */
function addSubPart(&$email, $part)
{
    //http://tools.ietf.org/html/rfc4021
    $new_part = null;
    $params = array();
    if (isset($part) && isset($email)) {
        if (isset($part->ctype_primary)) {
            $params['content_type'] = $part->ctype_primary;
        }
        if (isset($part->ctype_secondary)) {
            $params['content_type'] .= '/' . $part->ctype_secondary;
        }
        if (isset($part->ctype_parameters)) {
            foreach ($part->ctype_parameters as $k => $v) {
                if (strcasecmp($k, 'boundary') != 0) {
                    $params['content_type'] .= '; ' . $k . '=' . $v;
                }
            }
        }
        if (isset($part->disposition)) {
            $params['disposition'] = $part->disposition;
        }
        //FIXME: dfilename => filename
        if (isset($part->d_parameters)) {
            foreach ($part->d_parameters as $k => $v) {
                $params[$k] = $v;
            }
        }
        foreach ($part->headers as $k => $v) {
            switch ($k) {
                case "content-description":
                    $params['description'] = $v;
                    break;
                case "content-type":
                case "content-disposition":
                case "content-transfer-encoding":
                    // Do nothing, we already did
                    break;
                case "content-id":
                    $params['cid'] = str_replace('<', '', str_replace('>', '', $v));
                    break;
                default:
                    $params[$k] = $v;
                    break;
            }
        }
        // If not exist body, the part will be multipart/alternative, so we don't add encoding
        if (!isset($params['encoding']) && isset($part->body)) {
            $params['encoding'] = 'base64';
        }
        // We could not have body; recursive messages
        $new_part = $email->addSubPart(isset($part->body) ? $part->body : "", $params);
        unset($params);
    }
    // return the new part
    return $new_part;
}
Example #13
0
    /**
     * Encodes a header value as per RFC2047
     *
     * @param string $value      The header data to encode
     * @param string $charset    Character set name
     * @param string $encoding   Encoding name (base64 or quoted-printable)
     * @param int    $prefix_len Prefix length. Default: 0
     * @param string $eol        End-of-line sequence. Default: "\r\n"
     *
     * @return string            Encoded header data
     * @access public
     * @since 1.6.1
     */
    function encodeHeaderValue($value, $charset, $encoding, $prefix_len=0, $eol="\r\n")
    {
        if ($encoding == 'base64') {
            // Base64 encode the entire string
            $value = base64_encode($value);

            // Generate the header using the specified params and dynamicly 
            // determine the maximum length of such strings.
            // 75 is the value specified in the RFC.
            $prefix = '=?' . $charset . '?B?';
            $suffix = '?=';
            $maxLength = 75 - strlen($prefix . $suffix) - 2;
            $maxLength1stLine = $maxLength - $prefix_len;

            // We can cut base4 every 4 characters, so the real max
            // we can get must be rounded down.
            $maxLength = $maxLength - ($maxLength % 4);
            $maxLength1stLine = $maxLength1stLine - ($maxLength1stLine % 4);

            $cutpoint = $maxLength1stLine;
            $value_out = $value;
            $output = '';
            while ($value_out) {
                // Split translated string at every $maxLength
                $part = substr($value_out, 0, $cutpoint);
                $value_out = substr($value_out, $cutpoint);
                $cutpoint = $maxLength;
                // RFC 2047 specifies that any split header should
                // be seperated by a CRLF SPACE. 
                if ($output) {
                    $output .= $eol . ' ';
                }
                $output .= $prefix . $part . $suffix;
            }
            $value = $output;
        } else {
            // quoted-printable encoding has been selected
            $value = Mail_mimePart::encodeQP($value);

            // Generate the header using the specified params and dynamicly 
            // determine the maximum length of such strings.
            // 75 is the value specified in the RFC.
            $prefix = '=?' . $charset . '?Q?';
            $suffix = '?=';
            $maxLength = 75 - strlen($prefix . $suffix) - 3;
            $maxLength1stLine = $maxLength - $prefix_len;
            $maxLength = $maxLength - 1;

            // This regexp will break QP-encoded text at every $maxLength
            // but will not break any encoded letters.
            $reg = "/(([\^\$\*\-\+\.\|\'\";\(\)\[\]\{\}\/\\\\<>,@`!#%&:_a-zA-Z0-9]|=3D|=5F|=3F|=C[\d\w]=.{2}|=D\d=.{2}|=E\d=.{2}=.{2})+)/";

            $value_out = $value;
            $realMax = $maxLength1stLine + strlen($prefix . $suffix);
            if (strlen($value_out) >= $realMax) {
                // Begin with the regexp length for the first line.
                $regLength = $maxLength1stLine;
                $output = '';
                while ($value_out) {
                    // Split translated string at every $maxLength
                    // But make sure not to break any translated chars.
                    $found = preg_match($reg, substr($value_out, 0, $regLength), $matches);

                    // After this first line, we need to use a different
                    // regexp length for the first line.
                    $regLength = $maxLength;

                    // Save the found part and encapsulate it in the
                    // prefix & suffix. Then remove the part from the
                    // $value_out variable.
                    if ($found) {
                        $part = $matches[0];
                        $len = strlen($matches[0]);
                        $value_out = substr($value_out, $len);
                    } else {
                        $part = $value_out;
                        $value_out = "";
                    }

                    // RFC 2047 specifies that any split header should 
                    // be seperated by a CRLF SPACE
                    if ($output) {
                        $output .= $eol . ' ';
                    }
                    $output .= $prefix . $part . $suffix;
                }
                $value_out = $output;
            } else {
                $value_out = $prefix . $value_out . $suffix;
            }
            $value = $value_out;
        }

        return $value;
    }
    printf("NO UID\n");
}
$new_attendees = array();
$props = $ical->GetPropertiesByPath('VEVENT/ATTENDEE');
for ($i = 0; $i < count($props); $i++) {
    printf("Attendee Mailto '%s' Status '%s'\n", str_ireplace("MAILTO:", "", $props[$i]->Value()), $props[$i]->Parameters()["PARTSTAT"]);
}
$ical->SetCPParameterValue("VEVENT", "ATTENDEE", "RSVP", null);
// MODIFICATIONS
// METHOD
$ical->SetPValue("METHOD", "REPLY");
//ATTENDEE
$ical->SetCPParameterValue("VEVENT", "ATTENDEE", "PARTSTAT", "ACCEPTED");
$ical->SetCPParameterValue("VEVENT", "ATTENDEE", "PARTSTAT", "TENTATIVE", "MAILTO:user2@zpush.org");
printf("%s\n", $ical->Render());
$mail = new Mail_mimePart();
$headers = array("MIME-version" => "1.0", "From" => $mail->encodeHeader("from", "Pedro Picapiedra <*****@*****.**>", "UTF-8"), "To" => $mail->encodeHeader("to", "Pablo Marmol <*****@*****.**>", "UTF-8"), "Date" => gmdate("D, d M Y H:i:s", time()) . " GMT", "Subject" => $mail->encodeHeader("subject", "This is a subject", "UTF-8"), "Content-class" => "urn:content-classes:calendarmessage", "Content-transfer-encoding" => "8BIT");
$mail = new Mail_mimePart($ical->Render(), array("content_type" => "text/calendar; method=REPLY; charset=UTF-8", "headers" => $headers));
$message = "";
$encoded_mail = $mail->encode();
foreach ($encoded_mail["headers"] as $k => $v) {
    $message .= $k . ": " . $v . "\r\n";
}
$message .= "\r\n" . $encoded_mail["body"] . "\r\n";
printf("%s\n", $message);
$props = $ical->GetPropertiesByPath("VTIMEZONE/TZID");
if (count($props) > 0) {
    $tzid = $props[0]->Value();
    printf("TZID %s\n", $props[0]->Value());
}
print_r(TimezoneUtil::GetFullTZFromTZName($tzid));
 /**
  * Encodes a header as per RFC2047
  *
  * @param string $name     The header name
  * @param string $value    The header data to encode
  * @param string $charset  Character set name
  * @param string $encoding Encoding name (base64 or quoted-printable)
  *
  * @return string          Encoded header data (without a name)
  * @access public
  * @since 1.5.3
  */
 function encodeHeader($name, $value, $charset, $encoding)
 {
     return Mail_mimePart::encodeHeader($name, $value, $charset, $encoding, $this->_build_params['eol']);
 }
Example #16
0
 /**
  * Encode contexts
  *
  * @return none
  */
 public function encode()
 {
     $mimeType = Resources::MULTIPART_MIXED_TYPE;
     $batchGuid = Utilities::getGuid();
     $batchId = sprintf('batch_%s', $batchGuid);
     $contentType1 = array('content_type' => "{$mimeType}");
     $changeSetGuid = Utilities::getGuid();
     $changeSetId = sprintf('changeset_%s', $changeSetGuid);
     $contentType2 = array('content_type' => "{$mimeType}; boundary={$changeSetId}");
     $options = array('encoding' => 'binary', 'content_type' => Resources::HTTP_TYPE);
     // Create changeset MIME part
     $changeSet = new \Mail_mimePart();
     $i = 1;
     foreach ($this->_contexts as $context) {
         $context->addHeader(Resources::CONTENT_ID, $i);
         $changeSet->addSubpart((string) $context, $options);
         $i++;
     }
     // Encode the changeset MIME part
     $changeSetEncoded = $changeSet->encode($changeSetId);
     // Create the batch MIME part
     $batch = new \Mail_mimePart(Resources::EMPTY_STRING, $contentType1);
     // Add changeset encoded to batch MIME part
     $batch->addSubpart($changeSetEncoded['body'], $contentType2);
     // Encode batch MIME part
     $batchEncoded = $batch->encode($batchId);
     $this->_headers = $batchEncoded['headers'];
     $this->_body = $batchEncoded['body'];
 }
 /**
  * Builds the multipart message.
  *
  * @param array    $params    Build parameters that change the way the email
  *                            is built. Should be associative. See $_build_params.
  * @param resource $filename  Output file where to save the message instead of
  *                            returning it
  * @param boolean  $skip_head True if you want to return/save only the message
  *                            without headers
  *
  * @return mixed The MIME message content string, null or PEAR error object
  */
 public function get($params = null, $filename = null, $skip_head = false)
 {
     if (isset($params)) {
         while (list($key, $value) = each($params)) {
             $this->build_params[$key] = $value;
         }
     }
     $this->checkParams();
     if ($this->type == self::PGP_SIGNED) {
         $params = array('preamble' => "This is an OpenPGP/MIME signed message (RFC 4880 and 3156)", 'content_type' => "multipart/signed; micalg=pgp-sha1; protocol=\"application/pgp-signature\"", 'eol' => $this->build_params['eol']);
         $message = new Mail_mimePart('', $params);
         if (!empty($this->body)) {
             $headers = $this->message->headers();
             $params = array('content_type' => $headers['Content-Type']);
             if ($headers['Content-Transfer-Encoding']) {
                 $params['encoding'] = $headers['Content-Transfer-Encoding'];
             }
             $message->addSubpart($this->body, $params);
         }
         if (!empty($this->signature)) {
             $message->addSubpart($this->signature, array('filename' => 'signature.asc', 'content_type' => 'application/pgp-signature', 'disposition' => 'attachment', 'description' => 'OpenPGP digital signature'));
         }
     } else {
         if ($this->type == self::PGP_ENCRYPTED) {
             $params = array('preamble' => "This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156)", 'content_type' => "multipart/encrypted; protocol=\"application/pgp-encrypted\"", 'eol' => $this->build_params['eol']);
             $message = new Mail_mimePart('', $params);
             $message->addSubpart('Version: 1', array('content_type' => 'application/pgp-encrypted', 'description' => 'PGP/MIME version identification'));
             $message->addSubpart($this->encrypted, array('content_type' => 'application/octet-stream', 'description' => 'PGP/MIME encrypted message', 'disposition' => 'inline', 'filename' => 'encrypted.asc'));
         }
     }
     // Use saved boundary
     if (!empty($this->build_params['boundary'])) {
         $boundary = $this->build_params['boundary'];
     } else {
         $boundary = null;
     }
     // Write output to file
     if ($filename) {
         // Append mimePart message headers and body into file
         $headers = $message->encodeToFile($filename, $boundary, $skip_head);
         if ($this->isError($headers)) {
             return $headers;
         }
         $this->headers = array_merge($this->headers, $headers);
         return null;
     } else {
         $output = $message->encode($boundary, $skip_head);
         if ($this->isError($output)) {
             return $output;
         }
         $this->headers = array_merge($this->headers, $output['headers']);
         return $output['body'];
     }
 }
Example #18
0
 /**
  * Add text parts to a mimepart object
  *
  * @param Mail_mimePart $email reference to the object
  * @param Mail_mimeDecode $message reference to the message
  *
  * @access private
  * @return void
  */
 private function addTextPartsMessage(&$email, &$message)
 {
     $htmlBody = $plainBody = '';
     Mail_mimeDecode::getBodyRecursive($message, "html", $htmlBody);
     Mail_mimeDecode::getBodyRecursive($message, "plain", $plainBody);
     $altEmail = new Mail_mimePart('', array('content_type' => 'multipart/alternative'));
     if (strlen($htmlBody) > 0) {
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->addTextPartsMessage(): The message has HTML body"));
         $altEmail->addSubPart($htmlBody, array('content_type' => 'text/html; charset=utf-8', 'encoding' => 'base64'));
     }
     if (strlen($plainBody) > 0) {
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->addTextPartsMessage(): The message has PLAIN body"));
         $altEmail->addSubPart($plainBody, array('content_type' => 'text/plain; charset=utf-8', 'encoding' => 'base64'));
     }
     $boundary = '=_' . md5(rand() . microtime());
     $altEmail = $altEmail->encode($boundary);
     $email->addSubPart($altEmail['body'], array('content_type' => 'multipart/alternative;' . "\n" . ' boundary="' . $boundary . '"'));
     unset($altEmail);
     unset($htmlBody);
     unset($plainBody);
 }
Example #19
0
    /**
     * Encodes a header value as per RFC2047
     *
     * @param string $value      The header data to encode
     * @param string $charset    Character set name
     * @param string $encoding   Encoding name (base64 or quoted-printable)
     * @param int    $prefix_len Prefix length. Default: 0
     * @param string $eol        End-of-line sequence. Default: "\r\n"
     *
     * @return string            Encoded header data
     * @access public
     * @since 1.6.1
     */
    function encodeHeaderValue($value, $charset, $encoding, $prefix_len=0, $eol="\r\n")
    {
        // #17311: Use multibyte aware method (requires mbstring extension)
        if ($result = Mail_mimePart::encodeMB($value, $charset, $encoding, $prefix_len, $eol)) {
            return $result;
        }

        // Generate the header using the specified params and dynamicly
        // determine the maximum length of such strings.
        // 75 is the value specified in the RFC.
        $encoding = $encoding == 'base64' ? 'B' : 'Q';
        $prefix = '=?' . $charset . '?' . $encoding .'?';
        $suffix = '?=';
        $maxLength = 75 - strlen($prefix . $suffix);
        $maxLength1stLine = $maxLength - $prefix_len;

        if ($encoding == 'B') {
            // Base64 encode the entire string
            $value = base64_encode($value);

            // We can cut base64 every 4 characters, so the real max
            // we can get must be rounded down.
            $maxLength = $maxLength - ($maxLength % 4);
            $maxLength1stLine = $maxLength1stLine - ($maxLength1stLine % 4);

            $cutpoint = $maxLength1stLine;
            $output = '';

            while ($value) {
                // Split translated string at every $maxLength
                $part = substr($value, 0, $cutpoint);
                $value = substr($value, $cutpoint);
                $cutpoint = $maxLength;
                // RFC 2047 specifies that any split header should
                // be seperated by a CRLF SPACE.
                if ($output) {
                    $output .= $eol . ' ';
                }
                $output .= $prefix . $part . $suffix;
            }
            $value = $output;
        } else {
            // quoted-printable encoding has been selected
            $value = Mail_mimePart::encodeQP($value);

            // This regexp will break QP-encoded text at every $maxLength
            // but will not break any encoded letters.
            $reg1st = "|(.{0,$maxLength1stLine}[^\=][^\=])|";
            $reg2nd = "|(.{0,$maxLength}[^\=][^\=])|";

            if (strlen($value) > $maxLength1stLine) {
                // Begin with the regexp for the first line.
                $reg = $reg1st;
                $output = '';
                while ($value) {
                    // Split translated string at every $maxLength
                    // But make sure not to break any translated chars.
                    $found = preg_match($reg, $value, $matches);

                    // After this first line, we need to use a different
                    // regexp for the first line.
                    $reg = $reg2nd;

                    // Save the found part and encapsulate it in the
                    // prefix & suffix. Then remove the part from the
                    // $value_out variable.
                    if ($found) {
                        $part = $matches[0];
                        $len = strlen($matches[0]);
                        $value = substr($value, $len);
                    } else {
                        $part = $value;
                        $value = '';
                    }

                    // RFC 2047 specifies that any split header should
                    // be seperated by a CRLF SPACE
                    if ($output) {
                        $output .= $eol . ' ';
                    }
                    $output .= $prefix . $part . $suffix;
                }
                $value = $output;
            } else {
                $value = $prefix . $value . $suffix;
            }
        }

        return $value;
    }
Example #20
0
function newpost2mail($data)
{
    global $config, $mode, $user, $post_data, $phpEx, $phpbb_root_path, $db;
    $version = "beta 21";
    // variables that can be used in newpost2mail.config.php to build an individial subject line
    $post_SITENAME = $config['sitename'];
    $post_FORUMNAME = $data['forum_name'];
    $post_MODE = $mode;
    $post_TOPICTITLE = $data['topic_title'];
    $post_SUBJECT = $post_data['post_subject'];
    $post_USERNAME = $user->data['username'];
    $post_IP = $data['poster_ip'];
    $post_HOST = @gethostbyaddr($post_IP);
    // 3rd party edit?
    if ($mode == "edit" and $post_data[username] != $user->data['username']) {
        $post_EDITOR = $user->data['username'];
        $post_USERNAME = $post_data[username];
    }
    // get forum parents
    foreach (get_forum_parents($post_data) as $temp) {
        $post_FORUMPARENTS .= $temp["0"] . " / ";
        $post_FORUMPARENTS_laquo .= $temp["0"] . " « ";
    }
    // read configuration
    include $phpbb_root_path . 'newpost2mail.config.php';
    // check if the actual mode is set for sending mails
    if ($n2m_MAIL_ON[$mode]) {
        // if there is a language set in newpost2mail.config.php then use that setting.
        // Otherwise read default language from board config and use that.
        $n2m_LANG ? $lang = $n2m_LANG : ($lang = $config['default_lang']);
        // get (translated) phrases and convert them to UTF8
        foreach ($n2m_TEXT[en] as $key => $value) {
            if ($n2m_TEXT[$lang][$key]) {
                $phrase[$key] = utf8_encode($n2m_TEXT[$lang][$key]);
            } else {
                $phrase[$key] = utf8_encode($n2m_TEXT[en][$key]);
            }
        }
        // set variables for later use
        $board_url = generate_board_url();
        if (substr($board_url, -1) != "/") {
            $board_url .= "/";
        }
        $forum_url = $board_url . "viewforum.php?f={$data['forum_id']}";
        $thread_url = $board_url . "viewtopic.php?f={$data['forum_id']}&t={$data['topic_id']}";
        $post_url = $board_url . "viewtopic.php?f={$data['forum_id']}&t={$data['topic_id']}&p={$data['post_id']}#p{$data['post_id']}";
        $u_profile_url = $board_url . "memberlist.php?mode=viewprofile&u={$post_data['poster_id']}";
        $e_profile_url = $board_url . "memberlist.php?mode=viewprofile&u={$post_data['post_edit_user']}";
        $reply_url = $board_url . "posting.php?mode=reply&f={$data['forum_id']}&t={$data['topic_id']}";
        $edit_url = $board_url . "posting.php?mode=edit&f={$data['forum_id']}&p={$data['post_id']}";
        $quote_url = $board_url . "posting.php?mode=quote&f={$data['forum_id']}&p={$data['post_id']}";
        $delete_url = $board_url . "posting.php?mode=delete&f={$data['forum_id']}&p={$data['post_id']}";
        $info_url = $board_url . "mcp.php?i=main&mode=post_details&f={$data['forum_id']}&p={$data['post_id']}";
        $pm_url = $board_url . "ucp.php?i=pm&mode=compose&action=quotepost&p={$data['post_id']}";
        $email_url = $board_url . "memberlist.php?mode=email&u={$post_data['poster_id']}";
        // build the email header
        include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
        $headers .= "Date: " . date("D, j M Y H:i:s O") . "\n";
        $from = html_entity_decode($user->data['username']) . " <" . (($user->data['user_allow_viewemail'] or $n2m_ALWAYS_SHOW_EMAIL) ? $user->data['user_email'] : $user->data['username'] . "@aegee.org") . ">";
        $headers .= "From: " . Mail_mimePart::encodeHeader("from", $from, "UTF-8") . "\n";
        $headers .= "X-Mailer: newpost2mail {$version} for phpBB3\n";
        $headers .= "MIME-Version: 1.0\n";
        $headers .= "Content-type: text/plain; charset=UTF-8; format=flowed\n";
        // build the email body
        $message = html_entity_decode(str_replace("<br />", "<br />\n", generate_text_for_edit($data[message], $data[bbcode_uid], $post_data[forum_desc_options])["text"]) . "\n\n");
        //convert BBCode to text/plain; format=flowed
        require_once 'JBBCode/Parser.php';
        class QuoteWithOption extends JBBCode\CodeDefinition
        {
            public function __construct()
            {
                parent::__construct();
                $this->setTagName("quote");
                $this->useOption = true;
            }
            public function asHtml(JBBCode\ElementNode $el)
            {
                $result = "\nQuote from " . $el->getAttribute()["quote"] . ":\n";
                foreach (preg_split("/\\R/", $this->getContent($el)) as $line) {
                    $result .= "> " . $line . "\n";
                }
                return $result . "\n";
            }
        }
        class QuoteWithoutOption extends JBBCode\CodeDefinition
        {
            public function __construct()
            {
                parent::__construct();
                $this->setTagName("quote");
            }
            public function asHtml(JBBCode\ElementNode $el)
            {
                $result = "\n";
                foreach (preg_split("/\\R/", $this->getContent($el)) as $line) {
                    $result .= "> " . $line . "\n";
                }
                return $result . "\n";
            }
        }
        $parser = new JBBCode\Parser();
        $builder = new JBBCode\CodeDefinitionBuilder('i', '/{param}/');
        $parser->addCodeDefinition($builder->build());
        $builder = new JBBCode\CodeDefinitionBuilder('u', '_{param}_');
        $parser->addCodeDefinition($builder->build());
        $builder = new JBBCode\CodeDefinitionBuilder('b', '*{param}*');
        $parser->addCodeDefinition($builder->build());
        $parser->addCodeDefinition(new QuoteWithOption());
        $parser->addCodeDefinition(new QuoteWithoutOption());
        $builder = new JBBCode\CodeDefinitionBuilder('code', '{param}');
        $parser->addCodeDefinition($builder->build());
        $builder = (new JBBCode\CodeDefinitionBuilder('color', '{param}'))->setUseOption(true);
        $parser->addCodeDefinition($builder->build());
        $builder = (new JBBCode\CodeDefinitionBuilder('size', '{param}'))->setUseOption(true);
        $parser->addCodeDefinition($builder->build());
        $parser->parse($message);
        $message = $parser->getAsHtml();
        // build the informational table
        $message .= "{$phrase['subject']}: {$post_SUBJECT}\n";
        $message .= "{$phrase['thread']}: {$post_TOPICTITLE} {$thread_url}\n";
        $message .= "{$phrase['forum']} : {$post_FORUMPARENTS_laquo}{$post_FORUMNAME} {$forum_url}\n";
        $message .= "{$phrase['actions']}:\n";
        $message .= "  Reply address in the AEGEE Forum: " . $reply_url . "\n";
        $message .= "  Post URL: " . $post_url . "\n";
        $message .= "  Info URL: " . $info_url . "\n\n";
        $message .= "--\nThis message is generated upon adding a new posting in the AEGEE Forum, https://www.aegee.org/forum . You can answer directly to the sender by clicking the reply button, if the sender has activated its @aegee.org address, and does not want to hide his/her identity, otherwise the sending address of this email does not exist.  Sending emails from the AEGEE forum is experimental.  Direct your feedback at forum@aegee.org .";
        if ($post_HOST == $post_IP) {
            $post_HOST = $phrase[host_na];
        }
        // build the post text table
        // search for inline attachments to show them in the post text
        if (!empty($data[attachment_data])) {
            parse_attachments($data[forum_id], $data[message], $data[attachment_data], $dummy, true);
        }
        // generate post text
        // show attachments if not already shown in the post text
        if (!empty($data[attachment_data])) {
            $message .= "{$phrase['attachments']}:\n";
            foreach ($data[attachment_data] as $filename) {
                $message .= "  " . print_r($filename, 1) . "\n";
            }
            $message .= "\n";
        }
        // add signature
        if ($n2m_SHOW_SIG) {
            if ($mode != "edit") {
                if ($user->data[user_sig] and $data[enable_sig]) {
                    $message .= "\nSignature:\n  ";
                    $message .= generate_text_for_edit($user->data[user_sig], $user->data[user_sig_bbcode_uid], $post_data[forum_desc_options])["text"] . "\n\n";
                }
            }
        }
        // encode subject
        $subject = mail_encode(html_entity_decode($n2m_SUBJECT));
        // convert all addresses to lowercase and delete any empty addresses
        foreach ($n2m_MAILTO as $key => $value) {
            if (is_null($value) or $value == "") {
                unset($n2m_MAILTO[$key]);
            } else {
                $n2m_MAILTO[$key] = strtolower($n2m_MAILTO[$key]);
            }
        }
        // insure that every address is only used once
        $n2m_MAILTO = array_unique($n2m_MAILTO);
        // Testversion, Mails an Author des Artikels verhindern
        // unset($n2m_MAILTO[array_search($user->data['user_email'], $n2m_MAILTO)]);
        // die($message); // for debugging purposes, mail will be shown in browser and not sent out if we uncomment this line
        // make text "flow" in plain/text
        $temp = $message;
        $message = '';
        foreach (preg_split("/\\R/", $temp) as $line) {
            $message .= wordwrap($line, 75, $line[0] == ">" ? " \r\n>" : " \r\n") . "\r\n";
        }
        // and finally send the mails
        foreach ($n2m_MAILTO as $mailto) {
            if ($config['smtp_delivery']) {
                // SMTP?
                $tempto[to][email] = $mailto;
                $to[to] = $tempto;
                $result = smtpmail($to, $subject, str_replace("\n.", "\n..", $message), $err_msg, $headers);
                reset($to);
                reset($tempto);
            } else {
                // or PHP mail?
                $result = $config['email_function_name']($mailto, $subject, $message, $headers);
            }
        }
    }
}