maildaemon correctly checks max notice length

This commit is contained in:
Evan Prodromou 2009-08-21 08:21:55 -04:00
parent a94a5fb51a
commit 1285c11d0a

View File

@ -66,9 +66,10 @@ class MailerDaemon
} }
$msg = $this->cleanup_msg($msg); $msg = $this->cleanup_msg($msg);
$msg = common_shorten_links($msg); $msg = common_shorten_links($msg);
if (mb_strlen($msg) > 140) { if (Notice::contentTooLong($msg)) {
$this->error($from,_('That\'s too long. '. $this->error($from, sprintf(_('That\'s too long. '.
'Max notice size is 140 chars.')); 'Max notice size is %d chars.'),
Notice::maxContent()));
} }
$fileRecords = array(); $fileRecords = array();
foreach($attachments as $attachment){ foreach($attachments as $attachment){
@ -78,9 +79,9 @@ class MailerDaemon
die('error() should trigger an exception before reaching here.'); die('error() should trigger an exception before reaching here.');
} }
$filename = $this->saveFile($user, $attachment,$mimetype); $filename = $this->saveFile($user, $attachment,$mimetype);
fclose($attachment); fclose($attachment);
if (empty($filename)) { if (empty($filename)) {
$this->error($from,_('Couldn\'t save file.')); $this->error($from,_('Couldn\'t save file.'));
} }
@ -96,9 +97,10 @@ class MailerDaemon
$short_fileurl = common_shorten_url($fileurl); $short_fileurl = common_shorten_url($fileurl);
$msg .= ' ' . $short_fileurl; $msg .= ' ' . $short_fileurl;
if (mb_strlen($msg) > 140) { if (Notice::contentTooLong($msg)) {
$this->deleteFile($filename); $this->deleteFile($filename);
$this->error($from,_('Max notice size is 140 chars, including attachment URL.')); $this->error($from, sprintf(_('Max notice size is %d chars, including attachment URL.'),
Notice::maxContent()));
} }
// Also, not sure this is necessary -- Zach // Also, not sure this is necessary -- Zach
@ -123,7 +125,7 @@ class MailerDaemon
$stream = stream_get_meta_data($attachment); $stream = stream_get_meta_data($attachment);
if (copy($stream['uri'], $filepath) && chmod($filepath,0664)) { if (copy($stream['uri'], $filepath) && chmod($filepath,0664)) {
return $filename; return $filename;
} else { } else {
$this->error(null,_('File could not be moved to destination directory.' . $stream['uri'] . ' ' . $filepath)); $this->error(null,_('File could not be moved to destination directory.' . $stream['uri'] . ' ' . $filepath));
} }
} }
@ -152,7 +154,7 @@ class MailerDaemon
} }
function maybeAddRedir($file_id, $url) function maybeAddRedir($file_id, $url)
{ {
$file_redir = File_redirection::staticGet('url', $url); $file_redir = File_redirection::staticGet('url', $url);
if (empty($file_redir)) { if (empty($file_redir)) {
@ -273,7 +275,7 @@ class MailerDaemon
} }
function attachFile($notice, $filerec) function attachFile($notice, $filerec)
{ {
File_to_post::processNew($filerec->id, $notice->id); File_to_post::processNew($filerec->id, $notice->id);
$this->maybeAddRedir($filerec->id, $this->maybeAddRedir($filerec->id,