$addlists = explode(',', $_GET['list']);
}
$addlists = cleanArray($addlists);
foreach ($addlists as $listid) {
$query = sprintf('replace into %s (messageid,listid,entered) values(%d,%d,now())', $GLOBALS['tables']['listmessage'], $id, $listid);
Sql_Query($query);
}
}
# 0008720: Using -p send from the commandline doesn't seem to work
if (!$GLOBALS['commandline']) {
Redirect($_GET['page'] . '&id=' . $id);
exit;
}
}
# load all message data
$messagedata = loadMessageData($id);
## auto generate the text version if empty
## hmm, might want this as config
/*
if (empty($messagedata['textmessage'])) {
include 'actions/generatetext.php';
}
*/
#var_dump($messagedata);
#exit;
#print '<h3>'.$messagedata['status'].'</h3>';
if (!empty($_GET['deletecriterion'])) {
include dirname(__FILE__) . '/actions/deletecriterion.php';
Redirect($_GET['page'] . '&id=' . $id . '&tab=' . $_GET['tab']);
}
ob_end_flush();
function repeatMessage($msgid)
{
# if (!USE_REPETITION && !USE_rss) return;
$data = loadMessageData($msgid);
## do not repeat when it has already been done
if ($data['repeatinterval'] == 0 || !empty($data['repeatedid'])) {
return;
}
# calculate the future embargo, a multiple of repeatinterval minutes after the current embargo
$msgdata = Sql_Fetch_Array_Query(sprintf('SELECT *,
embargo +
INTERVAL (FLOOR(TIMESTAMPDIFF(MINUTE, embargo, GREATEST(embargo, NOW())) / repeatinterval) + 1) * repeatinterval MINUTE AS newembargo
FROM %s
WHERE id = %d AND now() < repeatuntil', $GLOBALS['tables']['message'], $msgid));
if (!$msgdata) {
logEvent("Message {$msgid} not repeated due to reaching the repeatuntil date");
return;
}
# check whether the new embargo is not on an exclusion
if (isset($GLOBALS['repeat_exclude']) && is_array($GLOBALS['repeat_exclude'])) {
$loopcnt = 0;
while (excludedDateForRepetition($msgdata['newembargo'])) {
if (++$loopcnt > 15) {
logEvent("Unable to find new embargo date too many exclusions? for message {$msgid}");
return;
}
$result = Sql_Fetch_Array_Query(sprintf("SELECT '%s' + INTERVAL repeatinterval MINUTE AS newembargo\n FROM %s\n WHERE id = %d", $msgdata['newembargo'], $GLOBALS['tables']['message'], $msgid));
$msgdata['newembargo'] = $result['newembargo'];
}
}
# copy the new message
Sql_Query(sprintf('
insert into %s (entered) values(now())', $GLOBALS['tables']['message']));
$newid = Sql_Insert_id();
require dirname(__FILE__) . '/structure.php';
if (!is_array($DBstruct['message'])) {
logEvent("Error including structure when trying to duplicate message {$msgid}");
return;
}
foreach ($DBstruct['message'] as $column => $rec) {
if ($column != 'id' && $column != 'entered' && $column != 'sendstart') {
Sql_Query(sprintf('update %s set %s = "%s" where id = %d', $GLOBALS['tables']['message'], $column, addslashes($msgdata[$column]), $newid));
}
}
$req = Sql_Query(sprintf("SELECT *\n FROM %s\n WHERE id = %d AND name NOT IN ('id')", $GLOBALS['tables']['messagedata'], $msgid));
while ($row = Sql_Fetch_Array($req)) {
setMessageData($newid, $row['name'], $row['data']);
}
Sql_Query(sprintf('update %s set embargo = "%s",status = "submitted",sent = "" where id = %d', $GLOBALS['tables']['message'], $msgdata['newembargo'], $newid));
list($e['year'], $e['month'], $e['day'], $e['hour'], $e['minute'], $e['second']) = sscanf($msgdata['newembargo'], '%04d-%02d-%02d %02d:%02d:%02d');
unset($e['second']);
setMessageData($newid, 'embargo', $e);
foreach (array('processed', 'astext', 'ashtml', 'astextandhtml', 'aspdf', 'astextandpdf', 'viewed', 'bouncecount') as $item) {
Sql_Query(sprintf('update %s set %s = 0 where id = %d', $GLOBALS['tables']['message'], $item, $newid));
}
# lists
$req = Sql_Query(sprintf('select listid from %s where messageid = %d', $GLOBALS['tables']['listmessage'], $msgid));
while ($row = Sql_Fetch_Row($req)) {
Sql_Query(sprintf('insert into %s (messageid,listid,entered) values(%d,%d,now())', $GLOBALS['tables']['listmessage'], $newid, $row[0]));
}
# attachments
$req = Sql_Query(sprintf('select * from %s,%s where %s.messageid = %d and %s.attachmentid = %s.id', $GLOBALS['tables']['message_attachment'], $GLOBALS['tables']['attachment'], $GLOBALS['tables']['message_attachment'], $msgid, $GLOBALS['tables']['message_attachment'], $GLOBALS['tables']['attachment']));
while ($row = Sql_Fetch_Array($req)) {
if (is_file($row['remotefile'])) {
# if the "remote file" is actually local, we want to refresh the attachment, so we set
# filename to nothing
$row['filename'] = '';
}
Sql_Query(sprintf('insert into %s (filename,remotefile,mimetype,description,size)
values("%s","%s","%s","%s",%d)', $GLOBALS['tables']['attachment'], addslashes($row['filename']), addslashes($row['remotefile']), addslashes($row['mimetype']), addslashes($row['description']), $row['size']));
$attid = Sql_Insert_id();
Sql_Query(sprintf('insert into %s (messageid,attachmentid) values(%d,%d)', $GLOBALS['tables']['message_attachment'], $newid, $attid));
}
logEvent("Message {$msgid} was successfully rescheduled as message {$newid}");
## remember we duplicated, in order to avoid doing it again (eg when requeuing)
setMessageData($msgid, 'repeatedid', $newid);
if (getConfig('pqchoice') == 'phplistdotcom') {
activateRemoteQueue();
}
}
function precacheMessage($messageid, $forwardContent = 0)
{
global $cached;
$domain = getConfig('domain');
# $message = Sql_query("select * from {$GLOBALS["tables"]["message"]} where id = $messageid");
# $cached[$messageid] = array();
# $message = Sql_fetch_array($message);
$message = loadMessageData($messageid);
## the reply to is actually not in use
if (preg_match("/([^ ]+@[^ ]+)/", $message["replyto"], $regs)) {
# if there is an email in the from, rewrite it as "name <email>"
$message["replyto"] = str_replace($regs[0], "", $message["replyto"]);
$cached[$messageid]["replytoemail"] = $regs[0];
# if the email has < and > take them out here
$cached[$messageid]["replytoemail"] = str_replace("<", "", $cached[$messageid]["replytoemail"]);
$cached[$messageid]["replytoemail"] = str_replace(">", "", $cached[$messageid]["replytoemail"]);
# make sure there are no quotes around the name
$cached[$messageid]["replytoname"] = str_replace('"', "", ltrim(rtrim($message["replyto"])));
} elseif (strpos($message["replyto"], " ")) {
# if there is a space, we need to add the email
$cached[$messageid]["replytoname"] = $message["replyto"];
$cached[$messageid]["replytoemail"] = "listmaster@{$domain}";
} else {
if (!empty($message["replyto"])) {
$cached[$messageid]["replytoemail"] = $message["replyto"] . "@{$domain}";
## makes more sense not to add the domain to the word, but the help says it does
## so let's keep it for now
$cached[$messageid]["replytoname"] = $message["replyto"] . "@{$domain}";
}
}
$cached[$messageid]["fromname"] = $message["fromname"];
$cached[$messageid]["fromemail"] = $message["fromemail"];
$cached[$messageid]["to"] = $message["tofield"];
#0013076: different content when forwarding 'to a friend'
$cached[$messageid]["subject"] = $forwardContent ? stripslashes($message["forwardsubject"]) : $message["subject"];
#0013076: different content when forwarding 'to a friend'
$cached[$messageid]["content"] = $forwardContent ? stripslashes($message["forwardmessage"]) : $message["message"];
if (USE_MANUAL_TEXT_PART && !$forwardContent) {
$cached[$messageid]["textcontent"] = $message["textmessage"];
} else {
$cached[$messageid]["textcontent"] = '';
}
# var_dump($cached);exit;
#0013076: different content when forwarding 'to a friend'
$cached[$messageid]["footer"] = $forwardContent ? stripslashes($message["forwardfooter"]) : $message["footer"];
if (strip_tags($cached[$messageid]["footer"]) != $cached[$messageid]["footer"]) {
$cached[$messageid]["textfooter"] = HTML2Text($cached[$messageid]["footer"]);
$cached[$messageid]["htmlfooter"] = $cached[$messageid]["footer"];
} else {
$cached[$messageid]["textfooter"] = $cached[$messageid]["footer"];
$cached[$messageid]["htmlfooter"] = parseText($cached[$messageid]["footer"]);
}
$cached[$messageid]["htmlformatted"] = strip_tags($cached[$messageid]["content"]) != $cached[$messageid]["content"];
$cached[$messageid]["sendformat"] = $message["sendformat"];
if ($message["template"]) {
$req = Sql_Fetch_Row_Query("select template from {$GLOBALS["tables"]["template"]} where id = {$message["template"]}");
$cached[$messageid]["template"] = stripslashes($req[0]);
$cached[$messageid]["templateid"] = $message["template"];
# dbg("TEMPLATE: ".$req[0]);
} else {
$cached[$messageid]["template"] = '';
$cached[$messageid]["templateid"] = 0;
}
## @@ put this here, so it can become editable per email sent out at a later stage
$cached[$messageid]["html_charset"] = 'UTF-8';
#getConfig("html_charset");
## @@ need to check on validity of charset
if (!$cached[$messageid]["html_charset"]) {
$cached[$messageid]["html_charset"] = 'UTF-8';
#'iso-8859-1';
}
$cached[$messageid]["text_charset"] = 'UTF-8';
#getConfig("text_charset");
if (!$cached[$messageid]["text_charset"]) {
$cached[$messageid]["text_charset"] = 'UTF-8';
#'iso-8859-1';
}
## if we are sending a URL that contains user attributes, we cannot pre-parse the message here
## but that has quite some impact on speed. So check if that's the case and apply
$cached[$messageid]['userspecific_url'] = preg_match('/\\[.+\\]/', $message['sendurl']);
if (!$cached[$messageid]['userspecific_url']) {
## Fetch external content here, because URL does not contain placeholders
if ($GLOBALS["can_fetchUrl"] && preg_match("/\\[URL:([^\\s]+)\\]/i", $cached[$messageid]["content"], $regs)) {
$remote_content = fetchUrl($regs[1], array());
# $remote_content = fetchUrl($message['sendurl'],array());
# @@ don't use this
# $remote_content = includeStyles($remote_content);
if ($remote_content) {
$cached[$messageid]['content'] = str_replace($regs[0], $remote_content, $cached[$messageid]['content']);
# $cached[$messageid]['content'] = $remote_content;
$cached[$messageid]["htmlformatted"] = strip_tags($remote_content) != $remote_content;
## 17086 - disregard any template settings when we have a valid remote URL
$cached[$messageid]["template"] = NULL;
$cached[$messageid]["templateid"] = NULL;
} else {
#print Error(s('unable to fetch web page for sending'));
logEvent("Error fetching URL: " . $message['sendurl'] . ' cannot proceed');
return false;
}
}
//.........这里部分代码省略.........
function forwardPage($id)
{
global $tables;
$ok = true;
$subtitle = '';
$info = '';
$html = '';
$form = '';
$personalNote = '';
## Check requirements
# message
$mid = 0;
if (isset($_REQUEST['mid'])) {
$mid = sprintf('%d', $_REQUEST['mid']);
$messagedata = loadMessageData($mid);
$mid = $messagedata['id'];
if ($mid) {
$subtitle = $GLOBALS['strForwardSubtitle'] . ' ' . stripslashes($messagedata['subject']);
}
}
#mid set
# user
if (!isset($_REQUEST['uid']) || !$_REQUEST['uid']) {
FileNotFound();
}
## get userdata
$req = Sql_Query(sprintf('select * from %s where uniqid = "%s"', $tables['user'], sql_escape($_REQUEST['uid'])));
$userdata = Sql_Fetch_Array($req);
## verify that this subscriber actually received this message to forward, otherwise they're not allowed
$allowed = Sql_Fetch_Row_Query(sprintf('select userid from %s where userid = %d and messageid = %d', $GLOBALS['tables']['usermessage'], $userdata['id'], $mid));
if (empty($userdata['id']) || $allowed[0] != $userdata['id']) {
## when sending a test email as an admin, the entry isn't there yet
if (empty($_SESSION['adminloggedin']) || $_SESSION['adminloggedin'] != $_SERVER['REMOTE_ADDR']) {
FileNotFound('<br/><i>' . $GLOBALS['I18N']->get('When testing the phpList forward functionality, you need to be logged in as an administrator.') . '</i><br/>');
}
}
$firstpage = 1;
## is this the initial page or a followup
# forward addresses
$forwardemail = '';
if (isset($_REQUEST['email']) && !empty($_REQUEST['email'])) {
$firstpage = 0;
$forwardPeriodCount = Sql_Fetch_Array_Query(sprintf('select count(user) from %s where date_add(time,interval %s) >= now() and user = %d and status ="sent" ', $tables['user_message_forward'], FORWARD_EMAIL_PERIOD, $userdata['id']));
$forwardemail = stripslashes($_REQUEST['email']);
$emails = explode("\n", $forwardemail);
$emails = trimArray($emails);
$forwardemail = implode("\n", $emails);
#0011860: forward to friend, multiple emails
$emailCount = $forwardPeriodCount[0];
foreach ($emails as $index => $email) {
$emails[$index] = trim($email);
if (is_email($email)) {
++$emailCount;
} else {
$info .= sprintf('<br />' . $GLOBALS['strForwardInvalidEmail'], $email);
$ok = false;
}
}
if ($emailCount > FORWARD_EMAIL_COUNT) {
$info .= '<br />' . $GLOBALS['strForwardCountReached'];
$ok = false;
}
} else {
$ok = false;
}
#0011996: forward to friend - personal message
# text cannot be longer than max, to prevent very long text with only linefeeds total cannot be longer than twice max
if (FORWARD_PERSONAL_NOTE_SIZE && isset($_REQUEST['personalNote'])) {
if (strlen(strip_newlines($_REQUEST['personalNote'])) > FORWARD_PERSONAL_NOTE_SIZE || strlen($_REQUEST['personalNote']) > FORWARD_PERSONAL_NOTE_SIZE * 2) {
$info .= '<BR />' . $GLOBALS['strForwardNoteLimitReached'];
$ok = false;
}
$personalNote = strip_tags(htmlspecialchars_decode(stripslashes($_REQUEST['personalNote'])));
$userdata['personalNote'] = $personalNote;
}
if ($userdata['id'] && $mid) {
if ($ok && count($emails)) {
## All is well, send it
require_once 'admin/sendemaillib.php';
#0013845 Lead Ref Scheme
if (FORWARD_FRIEND_COUNT_ATTRIBUTE) {
$iCountFriends = FORWARD_FRIEND_COUNT_ATTRIBUTE;
} else {
$iCountFriends = 0;
}
if ($iCountFriends) {
$nFriends = intval(UserAttributeValue($userdata['id'], $iCountFriends));
}
## remember the lists for this message in order to notify only those admins
## that own them
$messagelists = array();
$messagelistsreq = Sql_Query(sprintf('select listid from %s where messageid = %d', $GLOBALS['tables']['listmessage'], $mid));
while ($row = Sql_Fetch_Row($messagelistsreq)) {
array_push($messagelists, $row[0]);
}
foreach ($emails as $index => $email) {
#0011860: forward to friend, multiple emails
$done = Sql_Fetch_Array_Query(sprintf('select user,status,time from %s where forward = "%s" and message = %d', $tables['user_message_forward'], $email, $mid));
$info .= '<br />' . $email . ': ';
if ($done['status'] === 'sent') {
//.........这里部分代码省略.........
function sendEmail($messageid, $email, $hash, $htmlpref = 0, $rssitems = array(), $forwardedby = array())
{
global $strThisLink, $PoweredByImage, $PoweredByText, $cached, $website;
if ($email == "") {
return 0;
}
#0013076: different content when forwarding 'to a friend'
if (FORWARD_ALTERNATIVE_CONTENT) {
$forwardContent = sizeof($forwardedby) > 0;
$messagedata = loadMessageData($messageid);
} else {
$forwardContent = 0;
}
if (empty($cached[$messageid])) {
$domain = getConfig("domain");
$message = Sql_query("select * from {$GLOBALS["tables"]["message"]} where id = {$messageid}");
$cached[$messageid] = array();
$message = Sql_fetch_array($message);
if (ereg("([^ ]+@[^ ]+)", $message["fromfield"], $regs)) {
# if there is an email in the from, rewrite it as "name <email>"
$message["fromfield"] = ereg_replace($regs[0], "", $message["fromfield"]);
$cached[$messageid]["fromemail"] = $regs[0];
# if the email has < and > take them out here
$cached[$messageid]["fromemail"] = ereg_replace("<", "", $cached[$messageid]["fromemail"]);
$cached[$messageid]["fromemail"] = ereg_replace(">", "", $cached[$messageid]["fromemail"]);
# make sure there are no quotes around the name
$cached[$messageid]["fromname"] = ereg_replace('"', "", ltrim(rtrim($message["fromfield"])));
} elseif (ereg(" ", $message["fromfield"], $regs)) {
# if there is a space, we need to add the email
$cached[$messageid]["fromname"] = $message["fromfield"];
$cached[$messageid]["fromemail"] = "listmaster@{$domain}";
} else {
$cached[$messageid]["fromemail"] = $message["fromfield"] . "@{$domain}";
## makes more sense not to add the domain to the word, but the help says it does
## so let's keep it for now
$cached[$messageid]["fromname"] = $message["fromfield"] . "@{$domain}";
}
# erase double spacing
while (ereg(" ", $cached[$messageid]["fromname"])) {
$cached[$messageid]["fromname"] = eregi_replace(" ", " ", $cached[$messageid]["fromname"]);
}
## this has weird effects when used with only one word, so take it out for now
# $cached[$messageid]["fromname"] = eregi_replace("@","",$cached[$messageid]["fromname"]);
$cached[$messageid]["fromname"] = trim($cached[$messageid]["fromname"]);
$cached[$messageid]["to"] = $message["tofield"];
#0013076: different content when forwarding 'to a friend'
$cached[$messageid]["subject"] = $forwardContent ? stripslashes($messagedata["forwardsubject"]) : $message["subject"];
$cached[$messageid]["replyto"] = $message["replyto"];
#0013076: different content when forwarding 'to a friend'
$cached[$messageid]["content"] = $forwardContent ? stripslashes($messagedata["forwardmessage"]) : $message["message"];
if (USE_MANUAL_TEXT_PART && !$forwardContent) {
$cached[$messageid]["textcontent"] = $message["textmessage"];
} else {
$cached[$messageid]["textcontent"] = '';
}
#0013076: different content when forwarding 'to a friend'
$cached[$messageid]["footer"] = $forwardContent ? stripslashes($messagedata["forwardfooter"]) : $message["footer"];
$cached[$messageid]["htmlformatted"] = $message["htmlformatted"];
$cached[$messageid]["sendformat"] = $message["sendformat"];
if ($message["template"]) {
$req = Sql_Fetch_Row_Query("select template from {$GLOBALS["tables"]["template"]} where id = {$message["template"]}");
$cached[$messageid]["template"] = stripslashes($req[0]);
$cached[$messageid]["templateid"] = $message["template"];
# dbg("TEMPLATE: ".$req[0]);
} else {
$cached[$messageid]["template"] = '';
$cached[$messageid]["templateid"] = 0;
}
## @@ put this here, so it can become editable per email sent out at a later stage
$cached[$messageid]["html_charset"] = getConfig("html_charset");
## @@ need to check on validity of charset
if (!$cached[$messageid]["html_charset"]) {
$cached[$messageid]["html_charset"] = 'iso-8859-1';
}
$cached[$messageid]["text_charset"] = getConfig("text_charset");
if (!$cached[$messageid]["text_charset"]) {
$cached[$messageid]["text_charset"] = 'iso-8859-1';
}
}
# else
# dbg("Using cached {$cached[$messageid]["fromemail"]}");
if (VERBOSE) {
output($GLOBALS['I18N']->get('sendingmessage') . ' ' . $messageid . ' ' . $GLOBALS['I18N']->get('withsubject') . ' ' . $cached[$messageid]["subject"] . ' ' . $GLOBALS['I18N']->get('to') . ' ' . $email);
}
# erase any placeholders that were not found
# $msg = ereg_replace("\[[A-Z ]+\]","",$msg);
#0011857: forward to friend, retain attributes
if ($hash == 'forwarded' && defined('KEEPFORWARDERATTRIBUTES') && KEEPFORWARDERATTRIBUTES) {
$user_att_values = getUserAttributeValues($forwardedby['email']);
} else {
$user_att_values = getUserAttributeValues($email);
}
$userdata = Sql_Fetch_Assoc_Query(sprintf('select * from %s where email = "%s"', $GLOBALS["tables"]["user"], $email));
$url = getConfig("unsubscribeurl");
$sep = ereg('\\?', $url) ? '&' : '?';
$html["unsubscribe"] = sprintf('<a href="%s%suid=%s">%s</a>', $url, $sep, $hash, $strThisLink);
$text["unsubscribe"] = sprintf('%s%suid=%s', $url, $sep, $hash);
$html["unsubscribeurl"] = sprintf('%s%suid=%s', $url, $sep, $hash);
$text["unsubscribeurl"] = sprintf('%s%suid=%s', $url, $sep, $hash);
#0013076: Blacklisting posibility for unknown users
//.........这里部分代码省略.........
function repeatMessage($msgid)
{
# if (!USE_REPETITION && !USE_rss) return;
$data = loadMessageData($msgid);
## do not repeat when it has already been done
if (!empty($data['repeatedid'])) {
return;
}
# get the future embargo, either "repeat" minutes after the old embargo
# or "repeat" after this very moment to make sure that we're not sending the
# message every time running the queue when there's no embargo set.
$msgdata = Sql_Fetch_Array_Query(sprintf('select *,date_add(embargo,interval repeatinterval minute) as newembargo,
date_add(now(),interval repeatinterval minute) as newembargo2, date_add(embargo,interval repeatinterval minute) > now() as isfuture
from %s where id = %d and repeatuntil > now()', $GLOBALS["tables"]["message"], $msgid));
if (!$msgdata["id"] || !$msgdata["repeatinterval"]) {
return;
}
# copy the new message
$query = ' insert into ' . $GLOBALS['tables']['message'] . ' (entered)' . ' values' . ' (current_timestamp)';
Sql_Query($query);
$newid = Sql_Insert_Id($GLOBALS['tables']['message'], 'id');
require dirname(__FILE__) . '/structure.php';
if (!is_array($DBstruct["message"])) {
logEvent("Error including structure when trying to duplicate message {$msgid}");
return;
}
foreach ($DBstruct["message"] as $column => $rec) {
if ($column != "id" && $column != "entered" && $column != "sendstart") {
Sql_Query(sprintf('update %s set %s = "%s" where id = %d', $GLOBALS["tables"]["message"], $column, addslashes($msgdata[$column]), $newid));
}
}
$req = Sql_Query(sprintf('select * from %s where id = %d', $GLOBALS['tables']['messagedata'], $msgid));
while ($row = Sql_Fetch_Array($req)) {
setMessageData($newid, $row['name'], $row['data']);
}
# check whether the new embargo is not on an exclusion
if (isset($GLOBALS["repeat_exclude"]) && is_array($GLOBALS["repeat_exclude"])) {
$repeatinterval = $msgdata["repeatinterval"];
$loopcnt = 0;
while (excludedDateForRepetition($msgdata["newembargo"])) {
$repeat += $msgdata["repeatinterval"];
$loopcnt++;
$msgdata = Sql_Fetch_Array_Query(sprintf('select *,date_add(embargo,interval %d minute) as newembargo,
date_add(current_timestamp,interval %d minute) as newembargo2, date_add(embargo,interval %d minute) > current_timestamp as isfuture
from %s where id = %d and repeatuntil > current_timestamp', $repeatinterval, $repeatinterval, $repeatinterval, $GLOBALS["tables"]["message"], $msgid));
if ($loopcnt > 15) {
logEvent("Unable to find new embargo date too many exclusions? for message {$msgid}");
return;
}
}
}
# correct some values
if (!$msgdata["isfuture"]) {
$msgdata["newembargo"] = $msgdata["newembargo2"];
}
Sql_Query(sprintf('update %s set embargo = "%s",status = "submitted",sent = "" where id = %d', $GLOBALS["tables"]["message"], $msgdata["newembargo"], $newid));
list($e['year'], $e['month'], $e['day'], $e['hour'], $e['minute'], $e['second']) = sscanf($msgdata["newembargo"], '%04d-%02d-%02d %02d:%02d:%02d');
unset($e['second']);
setMessageData($newid, 'embargo', $e);
foreach (array("processed", "astext", "ashtml", "astextandhtml", "aspdf", "astextandpdf", "viewed", "bouncecount") as $item) {
Sql_Query(sprintf('update %s set %s = 0 where id = %d', $GLOBALS["tables"]["message"], $item, $newid));
}
# lists
$req = Sql_Query(sprintf('select listid from %s where messageid = %d', $GLOBALS["tables"]["listmessage"], $msgid));
while ($row = Sql_Fetch_Row($req)) {
Sql_Query(sprintf('insert into %s (messageid,listid,entered) values(%d,%d,current_timestamp)', $GLOBALS["tables"]["listmessage"], $newid, $row[0]));
}
# attachments
$req = Sql_Query(sprintf('select * from %s,%s where %s.messageid = %d and %s.attachmentid = %s.id', $GLOBALS["tables"]["message_attachment"], $GLOBALS["tables"]["attachment"], $GLOBALS["tables"]["message_attachment"], $msgid, $GLOBALS["tables"]["message_attachment"], $GLOBALS["tables"]["attachment"]));
while ($row = Sql_Fetch_Array($req)) {
if (is_file($row["remotefile"])) {
# if the "remote file" is actually local, we want to refresh the attachment, so we set
# filename to nothing
$row["filename"] = "";
}
Sql_Query(sprintf('insert into %s (filename,remotefile,mimetype,description,size)
values("%s","%s","%s","%s",%d)', $GLOBALS["tables"]["attachment"], addslashes($row["filename"]), addslashes($row["remotefile"]), addslashes($row["mimetype"]), addslashes($row["description"]), $row["size"]));
$attid = Sql_Insert_Id($GLOBALS['tables']['attachment'], 'id');
Sql_Query(sprintf('insert into %s (messageid,attachmentid) values(%d,%d)', $GLOBALS["tables"]["message_attachment"], $newid, $attid));
}
logEvent("Message {$msgid} was successfully rescheduled as message {$newid}");
## remember we duplicated, in order to avoid doing it again (eg when requeuing)
setMessageData($msgid, 'repeatedid', $newid);
}
function precacheMessage($messageid, $forwardContent = 0)
{
global $cached, $tables;
$domain = getConfig('domain');
# $message = Sql_query("select * from {$GLOBALS["tables"]["message"]} where id = $messageid");
# $cached[$messageid] = array();
# $message = Sql_fetch_array($message);
$message = loadMessageData($messageid);
## the reply to is actually not in use
if (preg_match('/([^ ]+@[^ ]+)/', $message['replyto'], $regs)) {
# if there is an email in the from, rewrite it as "name <email>"
$message['replyto'] = str_replace($regs[0], '', $message['replyto']);
$cached[$messageid]['replytoemail'] = $regs[0];
# if the email has < and > take them out here
$cached[$messageid]['replytoemail'] = str_replace('<', '', $cached[$messageid]['replytoemail']);
$cached[$messageid]['replytoemail'] = str_replace('>', '', $cached[$messageid]['replytoemail']);
# make sure there are no quotes around the name
$cached[$messageid]['replytoname'] = str_replace('"', '', ltrim(rtrim($message['replyto'])));
} elseif (strpos($message['replyto'], ' ')) {
# if there is a space, we need to add the email
$cached[$messageid]['replytoname'] = $message['replyto'];
$cached[$messageid]['replytoemail'] = "listmaster@{$domain}";
} else {
if (!empty($message['replyto'])) {
$cached[$messageid]['replytoemail'] = $message['replyto'] . "@{$domain}";
## makes more sense not to add the domain to the word, but the help says it does
## so let's keep it for now
$cached[$messageid]['replytoname'] = $message['replyto'] . "@{$domain}";
}
}
$cached[$messageid]['fromname'] = $message['fromname'];
$cached[$messageid]['fromemail'] = $message['fromemail'];
$cached[$messageid]['to'] = $message['tofield'];
#0013076: different content when forwarding 'to a friend'
$cached[$messageid]['subject'] = $forwardContent ? stripslashes($message['forwardsubject']) : $message['subject'];
#0013076: different content when forwarding 'to a friend'
$cached[$messageid]['content'] = $forwardContent ? stripslashes($message['forwardmessage']) : $message['message'];
if (USE_MANUAL_TEXT_PART && !$forwardContent) {
$cached[$messageid]['textcontent'] = $message['textmessage'];
} else {
$cached[$messageid]['textcontent'] = '';
}
# var_dump($cached);exit;
#0013076: different content when forwarding 'to a friend'
$cached[$messageid]['footer'] = $forwardContent ? stripslashes($message['forwardfooter']) : $message['footer'];
if (strip_tags($cached[$messageid]['footer']) != $cached[$messageid]['footer']) {
$cached[$messageid]['textfooter'] = HTML2Text($cached[$messageid]['footer']);
$cached[$messageid]['htmlfooter'] = $cached[$messageid]['footer'];
} else {
$cached[$messageid]['textfooter'] = $cached[$messageid]['footer'];
$cached[$messageid]['htmlfooter'] = parseText($cached[$messageid]['footer']);
}
$cached[$messageid]['htmlformatted'] = strip_tags($cached[$messageid]['content']) != $cached[$messageid]['content'];
$cached[$messageid]['sendformat'] = $message['sendformat'];
if ($message['template']) {
$req = Sql_Fetch_Row_Query("select template from {$GLOBALS['tables']['template']} where id = {$message['template']}");
$cached[$messageid]['template'] = stripslashes($req[0]);
$cached[$messageid]['templateid'] = $message['template'];
# dbg("TEMPLATE: ".$req[0]);
} else {
$cached[$messageid]['template'] = '';
$cached[$messageid]['templateid'] = 0;
}
## @@ put this here, so it can become editable per email sent out at a later stage
$cached[$messageid]['html_charset'] = 'UTF-8';
#getConfig("html_charset");
## @@ need to check on validity of charset
if (!$cached[$messageid]['html_charset']) {
$cached[$messageid]['html_charset'] = 'UTF-8';
#'iso-8859-1';
}
$cached[$messageid]['text_charset'] = 'UTF-8';
#getConfig("text_charset");
if (!$cached[$messageid]['text_charset']) {
$cached[$messageid]['text_charset'] = 'UTF-8';
#'iso-8859-1';
}
## if we are sending a URL that contains user attributes, we cannot pre-parse the message here
## but that has quite some impact on speed. So check if that's the case and apply
$cached[$messageid]['userspecific_url'] = preg_match('/\\[.+\\]/', $message['sendurl']);
if (!$cached[$messageid]['userspecific_url']) {
## Fetch external content here, because URL does not contain placeholders
if ($GLOBALS['can_fetchUrl'] && preg_match("/\\[URL:([^\\s]+)\\]/i", $cached[$messageid]['content'], $regs)) {
$remote_content = fetchUrl($regs[1], array());
# $remote_content = fetchUrl($message['sendurl'],array());
# @@ don't use this
# $remote_content = includeStyles($remote_content);
if ($remote_content) {
$cached[$messageid]['content'] = str_replace($regs[0], $remote_content, $cached[$messageid]['content']);
# $cached[$messageid]['content'] = $remote_content;
$cached[$messageid]['htmlformatted'] = strip_tags($remote_content) != $remote_content;
## 17086 - disregard any template settings when we have a valid remote URL
$cached[$messageid]['template'] = null;
$cached[$messageid]['templateid'] = null;
} else {
#print Error(s('unable to fetch web page for sending'));
logEvent('Error fetching URL: ' . $message['sendurl'] . ' cannot proceed');
return false;
}
}
//.........这里部分代码省略.........
请发表评论