dodgeboard.com |
11-17-2006 10:19 PM |
Well, look this over Daniel and see if you can spot something that would be causing this.
PHP Code:
function vbms_api_send_message(
$to, $subject, $bbcode, $attachments = false, $xpriority = VBMS_XPRIORITY_NORMAL, $savecopy = true,
$addsignature = true, $reformatsignature = true, $testonly = false, $previewtype = false, $userid = 0)
{
// prep fields
$to = trim($to);
vbms_adjust_userid($userid);
if ($attachments === false)
{
$attachments = array();
}
if (!empty($to) and is_array($attachments) and $userid > 0)
{
global $DB_site, $bbuserinfo, $vboptions, $vbulletin;
// get missing data if not the current user
$permissions = vbms_get_permissions_by_userid($userid);
// set priority to normal if no permission
if ($xpriority != VBMS_XPRIORITY_NORMAL and !$permissions[VBMS_PERMISSIONS_CAN_USE_PRIORITIES])
{
$xpriority = VBMS_XPRIORITY_NORMAL;
}
// do attachment permission checks
if (!empty($attachments))
{
if (!$permissions[VBMS_PERMISSIONS_CAN_SEND_ATTACHMENTS])
{
return vbms_api_result::create_fail_instance("vbms_no_attachment_send_permissions");
}
else if (sizeof($attachments) > $permissions[VBMS_PERMISSIONS_MAX_ATTACHMENT_COUNT])
{
return vbms_api_result::create_fail_instance("vbms_too_many_attachments");
}
else if ($permissions[VBMS_PERMISSIONS_MAX_ATTACHMENT_FILESIZE] > 0)
{
// check bytes used
$totalbytes = 0;
foreach ($attachments as $attachment)
{
$totalbytes += $attachment['filesize'];
}
if ($totalbytes > $permissions[VBMS_PERMISSIONS_MAX_ATTACHMENT_FILESIZE])
{
$given = vb_number_format($totalbytes, 1, true);
$allowed = vb_number_format($permissions[VBMS_PERMISSIONS_MAX_ATTACHMENT_FILESIZE], 1, true);
return vbms_api_result::create_fail_instance("vbms_attachments_too_large", array($given, $allowed));
}
}
// check extensions
$allowedexts = vbms_get_valid_attachment_extensions();
foreach ($attachments as $attachment)
{
$extension = file_extension($attachment['filename']);
if (!in_array($extension, $allowedexts))
{
return vbms_api_result::create_fail_instance(
"vbms_denied_attachment_extension",
array(vbms_grammatical_implode($allowedexts)));
}
}
}
// load the signature, if necessary
if ($addsignature)
{
if ($userid != $bbuserinfo['userid'])
{
$user = $DB_site->query_first(
"SELECT signature
FROM " . TABLE_PREFIX . "usertextfield
WHERE userid = $userid");
$signature = $user['signature'];
}
else
{
$signature = $bbuserinfo['signature'];
}
}
// load alias and username, if necessary
if ($userid != $bbuserinfo['userid'])
{
$user = $DB_site->query_first(
"SELECT username, vbms_alias
FROM " . TABLE_PREFIX . "user
WHERE userid = $userid");
}
else
{
$user = $bbuserinfo;
}
$to = vbms_converttos($to);
// -----------------------------------------------------------------------
// construct a mail object and send it
// -----------------------------------------------------------------------
// construct
$object = new vbms_mail_message();
// set fields
$object->set_subject($subject);
$object->set_from($user['vbms_alias'], $user['username']);
$object->set_message_bbcode($bbcode);
$object->set_recipients($to);
$object->set_xpriority($xpriority);
// apply signature/trailer options
$object->apply_options($signature, $rewritesignature,
$permissions[VBMS_PERMISSIONS_REQUIRE_TRAILER],
$permissions[VBMS_PERMISSIONS_ABUSE_LEADER]);
// add attachments
foreach ($attachments as $attachment)
{
$object->add_attachment(
$attachment['filename'], $attachment['data'],
$attachment['mimetype']);
}
if ($previewtype !== false)
{
global $vbphrase, $stylevar;
$html = $object->construct_message_html($previewtype);
print_output($html);
return vbms_api_result::get_void_success_instance();
}
else
{
// send it
$result = $object->send($testonly);
if ($result !== true)
{
return vbms_api_result::create_fail_instance("vbms_senderror",
array(trim($result)));
}
else
{
// update floodcheck dateline
if ($permissions[VBMS_PERMISSIONS_SEND_FLOODCHECK] > 0)
{
$vbulletin->db->query(
"REPLACE INTO " . TABLE_PREFIX . "vbms_sendfloodcheck
(userid, dateline)
VALUES
($userid, " . TIMENOW . ")");
}
// add to sent messages (and increment quota)
if ($savecopy)
{
$bytes = sizeof($bbcode);
$bbcode = addslashes($bbcode);
$from = addslashes("\"" . $user['username'] . "\" <" .
$user['vbms_alias'] . "@" .
$vboptions['vbms_todomain'] . ">");
$subject = addslashes($subject);
$message = addslashes($bbcode);
$messageid = vbms_get_first_available_messageid();
$DB_site->query(
"INSERT INTO " . TABLE_PREFIX . "vbms_message
(messageid, format, userid, folderid, xpriority,
dateline, readflag, fromname, subject, message)
VALUES
($messageid, \"bbcode\", $userid, " .
VBMS_FOLDER_SENTMESSAGES . ", $xpriority,
" . TIMENOW . ", 1, \"$from\", \"$subject\",
\"$message\")");
vbms_api_adjust_quota_usage($bytes, $userid);
}
return vbms_api_result::get_void_success_instance();
}
}
}
else
{
return vbms_api_result::get_invalid_arguments_instance();
}
}
|