Review Changes

renamed some functions and adjusted corresponding calls.
This commit is contained in:
Adam Magness 2017-12-01 21:05:06 -05:00
parent e90b0748aa
commit 9a4e741d1a
9 changed files with 34 additions and 80 deletions

View File

@ -79,30 +79,10 @@ function update_fail($update_id, $error_message) {
'to_email' => $admin['email'], 'to_email' => $admin['email'],
'preamble' => $preamble, 'preamble' => $preamble,
'body' => $body, 'body' => $body,
'language' => $lang, 'language' => $lang)
)); );
} }
/*
@TODO deprecated code?
$email_tpl = get_intltext_template("update_fail_eml.tpl");
$email_msg = replace_macros($email_tpl, array(
'$sitename' => $a->config['sitename'],
'$siteurl' => System::baseUrl(),
'$update' => DB_UPDATE_VERSION,
'$error' => sprintf(t('Update %s failed. See error logs.'), DB_UPDATE_VERSION)
));
$subject=sprintf(t('Update Error at %s'), System::baseUrl());
$subject = Email::emailHeaderEncode($subject,'UTF-8'); // use Friendica\Protocol\Email;
mail($a->config['admin_email'], $subject, $email_msg,
'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME']."\n"
.'Content-type: text/plain; charset=UTF-8'."\n"
.'Content-transfer-encoding: 8bit');
*/
//try the logger //try the logger
logger("CRITICAL: Database structure update failed: ".$retval); logger("CRITICAL: Database structure update failed: ".$retval);
} }

View File

@ -75,7 +75,7 @@ function invite_post(App $a) {
$nmessage = $message; $nmessage = $message;
} }
$res = mail($recip, Email::emailHeaderEncode(t('Please join us on Friendica'),'UTF-8'), $res = mail($recip, Email::encodeHeader(t('Please join us on Friendica'),'UTF-8'),
$nmessage, $nmessage,
"From: " . $a->user['email'] . "\n" "From: " . $a->user['email'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n" . 'Content-type: text/plain; charset=UTF-8' . "\n"

View File

@ -1032,9 +1032,9 @@ function item_post(App $a) {
$disclaimer .= sprintf( t('You may visit them online at %s'), System::baseUrl() . '/profile/' . $a->user['nickname']) . EOL; $disclaimer .= sprintf( t('You may visit them online at %s'), System::baseUrl() . '/profile/' . $a->user['nickname']) . EOL;
$disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL; $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
if (!$datarray['title']=='') { if (!$datarray['title']=='') {
$subject = Email::emailHeaderEncode($datarray['title'], 'UTF-8'); $subject = Email::encodeHeader($datarray['title'], 'UTF-8');
} else { } else {
$subject = Email::emailHeaderEncode('[Friendica]' . ' ' . sprintf( t('%s posted an update.'), $a->user['username']), 'UTF-8'); $subject = Email::encodeHeader('[Friendica]' . ' ' . sprintf( t('%s posted an update.'), $a->user['username']), 'UTF-8');
} }
$link = '<a href="' . System::baseUrl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />'; $link = '<a href="' . System::baseUrl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
$html = prepare_body($datarray); $html = prepare_body($datarray);

View File

@ -265,7 +265,7 @@ function settings_post(App $a) {
if (strlen($eacct['server'])) { if (strlen($eacct['server'])) {
$dcrpass = ''; $dcrpass = '';
openssl_private_decrypt(hex2bin($eacct['pass']), $dcrpass, $a->user['prvkey']); openssl_private_decrypt(hex2bin($eacct['pass']), $dcrpass, $a->user['prvkey']);
$mbox = Email::emailConnect($mb, $mail_user, $dcrpass); $mbox = Email::connect($mb, $mail_user, $dcrpass);
unset($dcrpass); unset($dcrpass);
if (!$mbox) { if (!$mbox) {
$failed = true; $failed = true;

View File

@ -1520,13 +1520,13 @@ class Probe
$mailbox = Email::constructMailboxName($r[0]); $mailbox = Email::constructMailboxName($r[0]);
$password = ''; $password = '';
openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']); openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']);
$mbox = Email::emailConnect($mailbox, $r[0]['user'], $password); $mbox = Email::connect($mailbox, $r[0]['user'], $password);
if (!mbox) { if (!mbox) {
return false; return false;
} }
} }
$msgs = Email::emailPoll($mbox, $uri); $msgs = Email::poll($mbox, $uri);
logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG); logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);
if (!count($msgs)) { if (!count($msgs)) {
@ -1546,7 +1546,7 @@ class Probe
$data["notify"] = 'smtp '.random_string(); $data["notify"] = 'smtp '.random_string();
$data["poll"] = 'email '.random_string(); $data["poll"] = 'email '.random_string();
$x = Email::emailMsgMeta($mbox, $msgs[0]); $x = Email::messageMeta($mbox, $msgs[0]);
if (stristr($x[0]->from, $uri)) { if (stristr($x[0]->from, $uri)) {
$adr = imap_rfc822_parse_adrlist($x[0]->from, ''); $adr = imap_rfc822_parse_adrlist($x[0]->from, '');
} elseif (stristr($x[0]->to, $uri)) { } elseif (stristr($x[0]->to, $uri)) {

View File

@ -19,7 +19,7 @@ class Email
* @param string $password The password * @param string $password The password
* @return object * @return object
*/ */
public static function emailConnect($mailbox, $username, $password) public static function connect($mailbox, $username, $password)
{ {
if (! function_exists('imap_open')) { if (! function_exists('imap_open')) {
return false; return false;
@ -35,7 +35,7 @@ class Email
* @param string $email_addr email * @param string $email_addr email
* @return array * @return array
*/ */
public static function emailPoll($mbox, $email_addr) public static function poll($mbox, $email_addr)
{ {
if (! ($mbox && $email_addr)) if (! ($mbox && $email_addr))
return array(); return array();
@ -83,44 +83,19 @@ class Email
* @param integer $uid user id * @param integer $uid user id
* @return mixed * @return mixed
*/ */
public static function emailMsgMeta($mbox, $uid) public static function messageMeta($mbox, $uid)
{ {
$ret = (($mbox && $uid) ? @imap_fetch_overview($mbox, $uid, FT_UID) : array(array())); // POSSIBLE CLEANUP --> array(array()) is probably redundant now $ret = (($mbox && $uid) ? @imap_fetch_overview($mbox, $uid, FT_UID) : array(array())); // POSSIBLE CLEANUP --> array(array()) is probably redundant now
return (count($ret)) ? $ret : array(); return (count($ret)) ? $ret : array();
} }
/**
* @brief Check addons, not called from main friendica project
* I don't see it in addons either
*/
function email_msg_headers($mbox, $uid) {
$raw_header = (($mbox && $uid) ? @imap_fetchheader($mbox,$uid,FT_UID) : '');
$raw_header = str_replace("\r",'',$raw_header);
$ret = array();
$h = explode("\n",$raw_header);
if (count($h))
foreach ($h as $line ) {
if (preg_match("/^[a-zA-Z]/", $line)) {
$key = substr($line,0,strpos($line,':'));
$value = substr($line,strpos($line,':')+1);
$last_entry = strtolower($key);
$ret[$last_entry] = trim($value);
}
else {
$ret[$last_entry] .= ' ' . trim($line);
}
}
return $ret;
}
/** /**
* @param object $mbox mailbox * @param object $mbox mailbox
* @param integer $uid user id * @param integer $uid user id
* @param string $reply reply * @param string $reply reply
* @return array * @return array
*/ */
public static function emailGetMsg($mbox, $uid, $reply) public static function getMessage($mbox, $uid, $reply)
{ {
$ret = array(); $ret = array();
@ -131,11 +106,11 @@ class Email
} }
if (! $struc->parts) { if (! $struc->parts) {
$ret['body'] = self::emailGetPart($mbox, $uid, $struc, 0, 'html'); $ret['body'] = self::messageGetPart($mbox, $uid, $struc, 0, 'html');
$html = $ret['body']; $html = $ret['body'];
if (trim($ret['body']) == '') { if (trim($ret['body']) == '') {
$ret['body'] = self::emailGetPart($mbox, $uid, $struc, 0, 'plain'); $ret['body'] = self::messageGetPart($mbox, $uid, $struc, 0, 'plain');
} else { } else {
$ret['body'] = html2bbcode($ret['body']); $ret['body'] = html2bbcode($ret['body']);
} }
@ -143,12 +118,12 @@ class Email
$text = ''; $text = '';
$html = ''; $html = '';
foreach ($struc->parts as $ptop => $p) { foreach ($struc->parts as $ptop => $p) {
$x = self::emailGetPart($mbox, $uid, $p, $ptop + 1, 'plain'); $x = self::messageGetPart($mbox, $uid, $p, $ptop + 1, 'plain');
if ($x) { if ($x) {
$text .= $x; $text .= $x;
} }
$x = self::emailGetPart($mbox, $uid, $p, $ptop + 1, 'html'); $x = self::messageGetPart($mbox, $uid, $p, $ptop + 1, 'html');
if ($x) { if ($x) {
$html .= $x; $html .= $x;
} }
@ -184,7 +159,7 @@ class Email
* @param string $subtype sub type * @param string $subtype sub type
* @return string * @return string
*/ */
private static function emailGetPart($mbox, $uid, $p, $partno, $subtype) private static function messageGetPart($mbox, $uid, $p, $partno, $subtype)
{ {
// $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple
global $htmlmsg,$plainmsg,$charset,$attachments; global $htmlmsg,$plainmsg,$charset,$attachments;
@ -257,7 +232,7 @@ class Email
if (isset($p->parts) && $p->parts) { if (isset($p->parts) && $p->parts) {
$x = ""; $x = "";
foreach ($p->parts as $partno0 => $p2) { foreach ($p->parts as $partno0 => $p2) {
$x .= self::emailGetPart($mbox, $uid, $p2, $partno . '.' . ($partno0+1), $subtype); // 1.2, 1.2.1, etc. $x .= self::messageGetPart($mbox, $uid, $p2, $partno . '.' . ($partno0+1), $subtype); // 1.2, 1.2.1, etc.
//if ($x) { //if ($x) {
// return $x; // return $x;
//} //}
@ -271,7 +246,7 @@ class Email
* @param string $charset character set * @param string $charset character set
* @return string * @return string
*/ */
public static function emailHeaderEncode($in_str, $charset) public static function encodeHeader($in_str, $charset)
{ {
$out_str = $in_str; $out_str = $in_str;
$need_to_convert = false; $need_to_convert = false;
@ -324,7 +299,7 @@ class Email
} }
/** /**
* Function emailSend is used by NETWORK_EMAIL and NETWORK_EMAIL2 code * Function send is used by NETWORK_EMAIL and NETWORK_EMAIL2 code
* (not to notify the user, but to send items to email contacts) * (not to notify the user, but to send items to email contacts)
* *
* @param string $addr address * @param string $addr address
@ -336,7 +311,7 @@ class Email
* *
* @todo This could be changed to use the Emailer class * @todo This could be changed to use the Emailer class
*/ */
public static function emailSend($addr, $subject, $headers, $item) public static function send($addr, $subject, $headers, $item)
{ {
//$headers .= 'MIME-Version: 1.0' . "\n"; //$headers .= 'MIME-Version: 1.0' . "\n";
//$headers .= 'Content-Type: text/html; charset=UTF-8' . "\n"; //$headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";

View File

@ -37,8 +37,8 @@ class Emailer
$email_textonly = PConfig::get($params['uid'], "system", "email_textonly"); $email_textonly = PConfig::get($params['uid'], "system", "email_textonly");
} }
$fromName = Email::emailHeaderEncode(html_entity_decode($params['fromName'], ENT_QUOTES, 'UTF-8'), 'UTF-8'); $fromName = Email::encodeHeader(html_entity_decode($params['fromName'], ENT_QUOTES, 'UTF-8'), 'UTF-8');
$messageSubject = Email::emailHeaderEncode(html_entity_decode($params['messageSubject'], ENT_QUOTES, 'UTF-8'), 'UTF-8'); $messageSubject = Email::encodeHeader(html_entity_decode($params['messageSubject'], ENT_QUOTES, 'UTF-8'), 'UTF-8');
// generate a mime boundary // generate a mime boundary
$mimeBoundary =rand(0, 9)."-" $mimeBoundary =rand(0, 9)."-"

View File

@ -418,19 +418,19 @@ class Delivery {
if ($r1 && $r1[0]['reply_to']) if ($r1 && $r1[0]['reply_to'])
$reply_to = $r1[0]['reply_to']; $reply_to = $r1[0]['reply_to'];
$subject = (($it['title']) ? Email::emailHeaderEncode($it['title'],'UTF-8') : t("\x28no subject\x29")) ; $subject = (($it['title']) ? Email::encodeHeader($it['title'],'UTF-8') : t("\x28no subject\x29")) ;
// only expose our real email address to true friends // only expose our real email address to true friends
if (($contact['rel'] == CONTACT_IS_FRIEND) && !$contact['blocked']) { if (($contact['rel'] == CONTACT_IS_FRIEND) && !$contact['blocked']) {
if ($reply_to) { if ($reply_to) {
$headers = 'From: '.Email::emailHeaderEncode($local_user[0]['username'],'UTF-8').' <'.$reply_to.'>'."\n"; $headers = 'From: '.Email::encodeHeader($local_user[0]['username'],'UTF-8').' <'.$reply_to.'>'."\n";
$headers .= 'Sender: '.$local_user[0]['email']."\n"; $headers .= 'Sender: '.$local_user[0]['email']."\n";
} else { } else {
$headers = 'From: '.Email::emailHeaderEncode($local_user[0]['username'],'UTF-8').' <'.$local_user[0]['email'].'>'."\n"; $headers = 'From: '.Email::encodeHeader($local_user[0]['username'],'UTF-8').' <'.$local_user[0]['email'].'>'."\n";
} }
} else { } else {
$headers = 'From: '. Email::emailHeaderEncode($local_user[0]['username'],'UTF-8') .' <'. t('noreply') .'@'.$a->get_hostname() .'>'. "\n"; $headers = 'From: '. Email::encodeHeader($local_user[0]['username'],'UTF-8') .' <'. t('noreply') .'@'.$a->get_hostname() .'>'. "\n";
} }
//if ($reply_to) //if ($reply_to)
@ -469,7 +469,7 @@ class Delivery {
if (strncasecmp($subject,'RE:',3)) if (strncasecmp($subject,'RE:',3))
$subject = 'Re: '.$subject; $subject = 'Re: '.$subject;
} }
Email::emailSend($addr, $subject, $headers, $it); Email::send($addr, $subject, $headers, $it);
} }
break; break;

View File

@ -331,7 +331,7 @@ Class OnePoll
$mailbox = Email::constructMailboxName($mailconf); $mailbox = Email::constructMailboxName($mailconf);
$password = ''; $password = '';
openssl_private_decrypt(hex2bin($mailconf['pass']), $password, $x['prvkey']); openssl_private_decrypt(hex2bin($mailconf['pass']), $password, $x['prvkey']);
$mbox = Email::emailConnect($mailbox, $mailconf['user'], $password); $mbox = Email::connect($mailbox, $mailconf['user'], $password);
unset($password); unset($password);
logger("Mail: Connect to " . $mailconf['user']); logger("Mail: Connect to " . $mailconf['user']);
if ($mbox) { if ($mbox) {
@ -344,12 +344,12 @@ Class OnePoll
} }
if ($mbox) { if ($mbox) {
$msgs = Email::emailPoll($mbox, $contact['addr']); $msgs = Email::poll($mbox, $contact['addr']);
if (count($msgs)) { if (count($msgs)) {
logger("Mail: Parsing ".count($msgs)." mails from ".$contact['addr']." for ".$mailconf['user'], LOGGER_DEBUG); logger("Mail: Parsing ".count($msgs)." mails from ".$contact['addr']." for ".$mailconf['user'], LOGGER_DEBUG);
$metas = Email::emailMsgMeta($mbox,implode(',', $msgs)); $metas = Email::messageMeta($mbox, implode(',', $msgs));
if (count($metas) != count($msgs)) { if (count($metas) != count($msgs)) {
logger("onepoll: for " . $mailconf['user'] . " there are ". count($msgs) . " messages but received " . count($metas) . " metas", LOGGER_DEBUG); logger("onepoll: for " . $mailconf['user'] . " there are ". count($msgs) . " messages but received " . count($metas) . " metas", LOGGER_DEBUG);
} else { } else {
@ -361,8 +361,7 @@ Class OnePoll
$datarray = array(); $datarray = array();
$datarray['verb'] = ACTIVITY_POST; $datarray['verb'] = ACTIVITY_POST;
$datarray['object-type'] = ACTIVITY_OBJ_NOTE; $datarray['object-type'] = ACTIVITY_OBJ_NOTE;
// $meta = Email::emailMsgMeta($mbox, $msg_uid); // $meta = Email::messageMeta($mbox, $msg_uid);
// $headers = email_msg_headers($mbox, $msg_uid);
$datarray['uri'] = Email::msgid2iri(trim($meta->message_id, '<>')); $datarray['uri'] = Email::msgid2iri(trim($meta->message_id, '<>'));
@ -466,7 +465,7 @@ Class OnePoll
$datarray['parent-uri'] = $datarray['uri']; $datarray['parent-uri'] = $datarray['uri'];
} }
$r = Email::emailGetMsg($mbox, $msg_uid, $reply); $r = Email::getMessage($mbox, $msg_uid, $reply);
if (!$r) { if (!$r) {
logger("Mail: can't fetch msg ".$msg_uid." for ".$mailconf['user']); logger("Mail: can't fetch msg ".$msg_uid." for ".$mailconf['user']);
continue; continue;