コード例 #1
0
function plugin_forumml_process_mail($plug, $reply = false)
{
    $request =& HTTPRequest::instance();
    $hp =& ForumML_HTMLPurifier::instance();
    // Instantiate a new Mail class
    $mail =& new Mail();
    // Build mail headers
    $to = mail_get_listname_from_list_id($request->get('list')) . "@" . $GLOBALS['sys_lists_host'];
    $mail->setTo($to);
    $from = user_getrealname(user_getid()) . " <" . user_getemail(user_getid()) . ">";
    $mail->setFrom($from);
    $vMsg = new Valid_Text('message');
    if ($request->valid($vMsg)) {
        $message = $request->get('message');
    }
    $subject = $request->get('subject');
    $mail->setSubject($subject);
    if ($reply) {
        // set In-Reply-To header
        $hres = plugin_forumml_get_message_headers($request->get('reply_to'));
        $reply_to = db_result($hres, 0, 'value');
        $mail->addAdditionalHeader("In-Reply-To", $reply_to);
    }
    $continue = true;
    if ($request->validArray(new Valid_Email('ccs')) && $request->exist('ccs')) {
        $cc_array = array();
        $idx = 0;
        foreach ($request->get('ccs') as $cc) {
            if (trim($cc) != "") {
                $cc_array[$idx] = $hp->purify($cc, CODENDI_PURIFIER_FULL);
                $idx++;
            }
        }
        // Checks sanity of CC List
        $err = '';
        if (!util_validateCCList($cc_array, $err)) {
            $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_forumml', 'invalid_mail', $err));
            $continue = false;
        } else {
            // add list of cc users to mail mime
            if (count($cc_array) > 0) {
                $cc_list = util_normalize_emails(implode(',', $cc_array));
                $mail->setCc($cc_list, true);
            }
        }
    }
    if ($continue) {
        // Process attachments
        // Define boundaries as specified in RFC:
        // http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
        $boundary = '----=_NextPart';
        $boundaryStart = '--' . $boundary;
        $boundaryEnd = '--' . $boundary . '--';
        // Attachments headers
        if (isset($_FILES["files"]) && count($_FILES["files"]['name']) > 0) {
            $attachment = "";
            $text = "This is a multi-part message in MIME format.\n";
            $text = "{$boundaryStart}\n";
            $text .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
            $text .= "Content-Transfer-Encoding: 8bit\n\n";
            $text .= $message;
            $text .= "\n\n";
            foreach ($_FILES["files"]['name'] as $i => $fileName) {
                $attachment .= "{$boundaryStart}\n";
                $attachment .= "Content-Type:" . $_FILES["files"]["type"][$i] . "; name=" . $fileName . "\n";
                $attachment .= "Content-Transfer-Encoding: base64\n";
                $attachment .= "Content-Disposition: attachment; filename=" . $fileName . "\n\n";
                $attachment .= chunk_split(base64_encode(file_get_contents($_FILES["files"]["tmp_name"][$i])));
            }
            $attachment .= "\n{$boundaryEnd}\n";
            $body = $text . $attachment;
            // force MimeType to multipart/mixed as default (when instantiating new Mail object) is text/plain
            $mail->setMimeType('multipart/mixed; boundary="' . $boundary . '"');
            $mail->addAdditionalHeader("MIME-Version", "1.0");
        } else {
            $body = $message;
        }
        $mail->setBody($body);
        if ($mail->send()) {
            $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_forumml', 'mail_succeed'));
        } else {
            $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_forumml', 'mail_fail'));
            $continue = false;
        }
    }
    return $continue;
}
コード例 #2
0
ファイル: index.php プロジェクト: pombredanne/tuleap
                $GLOBALS['Response']->addFeedback('warning', $GLOBALS['Language']->getText('plugin_forumml', 'delay_redirection', array($p->getThemePath() . "/images/ic/spinner-greenie.gif", $group_id, $list_id, 0)), CODENDI_PURIFIER_DISABLED);
            }
        }
    } else {
        $GLOBALS['Response']->addFeedback('warning', $GLOBALS['Language']->getText('plugin_forumml', 'warn_post_without_confirm'));
    }
    $params['title'] = 'ForumML';
    $params['group'] = $group_id;
    $params['toptab'] = 'mail';
    $params['help'] = "communication.html#mailing-lists";
    mail_header($params);
    if ($message_posted) {
        // wait few seconds before redirecting to archives page
        echo "<script> setTimeout('window.location=\"/plugins/forumml/message.php?group_id=" . $group_id . "&list=" . $list_id . "\"',3000) </script>";
    }
    $list_link = '<a href="/plugins/forumml/message.php?group_id=' . $group_id . '&list=' . $list_id . '">' . mail_get_listname_from_list_id($list_id) . '</a>';
    echo '<H2><b>' . $GLOBALS['Language']->getText('plugin_forumml', 'list_new_thread', array($list_link)) . '</b></H2>
	<a href="/plugins/forumml/message.php?group_id=' . $group_id . '&list=' . $list_id . '">[' . $GLOBALS["Language"]->getText('plugin_forumml', 'browse_arch') . ']</a><br><br>
	<H3><b>' . $GLOBALS['Language']->getText('plugin_forumml', 'new_thread') . '</b></H3>';
    // New thread form
    echo '<script type="text/javascript" src="scripts/cc_attach_js.php"></script>';
    echo "<form name='form' method='post' enctype='multipart/form-data'>\n\t<table>\n    <tr>\n\t\t<td valign='top' align='left'><b> " . $GLOBALS['Language']->getText('plugin_forumml', 'subject') . ":&nbsp;</b></td>\n\t\t<td align='left'><input type=text name='subject' size='80'></td>\n\t</tr></table>";
    echo '<table>
    <tr>
		<td align="left">
			<p><a href="javascript:;" onclick="addHeader(\'\',\'\',1);">[' . $GLOBALS["Language"]->getText('plugin_forumml', 'add_cc') . ']</a>
			 - <a href="javascript:;" onclick="addHeader(\'\',\'\',2);">[' . $GLOBALS["Language"]->getText('plugin_forumml', 'attach_file') . ']</a></p>
			<input type="hidden" value="0" id="header_val" />
			<div id="mail_header"></div></td></tr></table>';
    echo "<table><tr>\n\t\t\t<td valign='top' align='left'><b>" . $GLOBALS['Language']->getText('plugin_forumml', 'message') . "&nbsp;</b></td>\n\t\t\t<td align='left'><textarea rows='20' cols='100' name='message'></textarea></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td></td>\n\t\t\t<td><input type='submit' name='post' value='" . $GLOBALS['Language']->getText('global', 'btn_submit') . "'>\n\t\t\t\t<input type='reset' value='" . $GLOBALS['Language']->getText('plugin_forumml', 'erase') . "'></td>\n\t\t</tr>\n\t</table></form>";
    mail_footer($params);
コード例 #3
0
ファイル: message.php プロジェクト: nterray/tuleap
 $vList = new Valid_UInt('list');
 $vList->required();
 if (!$request->valid($vList)) {
     exit_error($GLOBALS["Language"]->getText('global', 'error'), $GLOBALS["Language"]->getText('plugin_forumml', 'specify_list'));
 } else {
     $list_id = $request->get('list');
     $project = ProjectManager::instance()->getProject($group_id);
     if (!$user->isMember($group_id) && ($user->isRestricted() || !mail_is_list_public($list_id) || !$project->isPublic())) {
         exit_error($GLOBALS["Language"]->getText('global', 'error'), $GLOBALS["Language"]->getText('include_exit', 'no_perm'));
     }
     if (!mail_is_list_active($list_id)) {
         exit_error($GLOBALS["Language"]->getText('global', 'error'), $GLOBALS["Language"]->getText('plugin_forumml', 'wrong_list'));
     }
 }
 // If the list is private, search if the current user is a member of that list. If not, permission denied
 $list_name = mail_get_listname_from_list_id($list_id);
 if (!mail_is_list_public($list_id)) {
     exec("{$GLOBALS['mailman_bin_dir']}/list_members " . $list_name, $members);
     $user = user_getemail(user_getid());
     if (!in_array($user, $members)) {
         exit_permission_denied();
     }
 }
 // Build the mail to be sent
 $vSrep = new Valid_WhiteList('send_reply', array('Submit'));
 $vSrep->required();
 if ($request->valid($vSrep)) {
     // process the mail
     $ret = plugin_forumml_process_mail($p, true);
     if ($ret) {
         $GLOBALS['Response']->addFeedback('warning', $GLOBALS['Language']->getText('plugin_forumml', 'delay_redirection', array($p->getThemePath() . "/images/ic/spinner-greenie.gif", $group_id, $list_id, $topic)), CODENDI_PURIFIER_DISABLED);
コード例 #4
0
ファイル: forumml_utils.php プロジェクト: pombredanne/tuleap
function plugin_forumml_process_mail($plug, $reply = false)
{
    $request =& HTTPRequest::instance();
    $hp =& ForumML_HTMLPurifier::instance();
    // Instantiate a new Mail class
    $mail = new Codendi_Mail();
    // Build mail headers
    $to = mail_get_listname_from_list_id($request->get('list')) . "@" . $GLOBALS['sys_lists_host'];
    $mail->setTo($to);
    $from = user_getrealname(user_getid()) . " <" . user_getemail(user_getid()) . ">";
    $mail->setFrom($from);
    $vMsg = new Valid_Text('message');
    if ($request->valid($vMsg)) {
        $message = $request->get('message');
    }
    $subject = $request->get('subject');
    $mail->setSubject($subject);
    if ($reply) {
        // set In-Reply-To header
        $hres = plugin_forumml_get_message_headers($request->get('reply_to'));
        $reply_to = db_result($hres, 0, 'value');
        $mail->addAdditionalHeader("In-Reply-To", $reply_to);
    }
    $continue = true;
    if ($request->validArray(new Valid_Email('ccs')) && $request->exist('ccs')) {
        $cc_array = array();
        $idx = 0;
        foreach ($request->get('ccs') as $cc) {
            if (trim($cc) != "") {
                $cc_array[$idx] = $hp->purify($cc, CODENDI_PURIFIER_FULL);
                $idx++;
            }
        }
        // Checks sanity of CC List
        $err = '';
        if (!util_validateCCList($cc_array, $err)) {
            $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_forumml', 'invalid_mail', $err));
            $continue = false;
        } else {
            // add list of cc users to mail mime
            if (count($cc_array) > 0) {
                $cc_list = util_normalize_emails(implode(',', $cc_array));
                $mail->setCc($cc_list, true);
            }
        }
    }
    if ($continue) {
        // Process attachments
        if (isset($_FILES["files"]) && count($_FILES["files"]['name']) > 0) {
            foreach ($_FILES["files"]['name'] as $i => $fileName) {
                $data = file_get_contents($_FILES["files"]["tmp_name"][$i]);
                $mime_type = $_FILES["files"]["type"][$i];
                $mail->addAttachment($data, $mime_type, $fileName);
            }
        }
        $mail->setBodyText($message);
        if ($mail->send()) {
            $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_forumml', 'mail_succeed'));
        } else {
            $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_forumml', 'mail_fail'));
            $continue = false;
        }
    }
    return $continue;
}