/**
  * 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']);
 }
示例#2
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']);
 }
    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));
/**
 * 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;
}
示例#5
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);
            }
        }
    }
}