]> git.mxchange.org Git - friendica.git/commitdiff
Review Changes
authorAdam Magness <adam.magness@gmail.com>
Sat, 2 Dec 2017 02:05:06 +0000 (21:05 -0500)
committerAdam Magness <adam.magness@gmail.com>
Sat, 2 Dec 2017 02:05:06 +0000 (21:05 -0500)
renamed some functions and adjusted corresponding calls.

include/dbstructure.php
mod/invite.php
mod/item.php
mod/settings.php
src/Network/Probe.php
src/Protocol/Email.php
src/Util/Emailer.php
src/Worker/Delivery.php
src/Worker/OnePoll.php

index f7a22196837dbac748f0c8f6baa7c8809b7f0704..cb2883d40d3bfa264dd8e0d63feaaca51351ddc5 100644 (file)
@@ -79,30 +79,10 @@ function update_fail($update_id, $error_message) {
                        'to_email' => $admin['email'],
                        'preamble' => $preamble,
                        '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
        logger("CRITICAL: Database structure update failed: ".$retval);
 }
index 2571bff927ec4838e1928baea82ca5fc067c93e0..06c0df3b84d5902ede461f243122182da7776d6f 100644 (file)
@@ -75,7 +75,7 @@ function invite_post(App $a) {
                        $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,
                        "From: " . $a->user['email'] . "\n"
                        . 'Content-type: text/plain; charset=UTF-8' . "\n"
index d8ecf50a4a431a2d9904e8e6046d6bce157e9c94..ffac1c8e445deb4dddb6c824212d77d83b7bb3fe 100644 (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 .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
                                if (!$datarray['title']=='') {
-                                       $subject = Email::emailHeaderEncode($datarray['title'], 'UTF-8');
+                                       $subject = Email::encodeHeader($datarray['title'], 'UTF-8');
                                } 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 />';
                                $html    = prepare_body($datarray);
index 1d7ac917826d7bedfe26c8575dab2e2b44a8cc47..af514e3a9f26410c85624a12252699699297c76a 100644 (file)
@@ -265,7 +265,7 @@ function settings_post(App $a) {
                                        if (strlen($eacct['server'])) {
                                                $dcrpass = '';
                                                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);
                                                if (!$mbox) {
                                                        $failed = true;
index 2216d7dcceaadabf4fc72198160820dcadc0241f..500aa7323fa42fc3b66ece4b4bdc9de1874202bf 100644 (file)
@@ -1520,13 +1520,13 @@ class Probe
                                $mailbox = Email::constructMailboxName($r[0]);
                                $password = '';
                                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) {
                                        return false;
                                }
                        }
 
-                       $msgs = Email::emailPoll($mbox, $uri);
+                       $msgs = Email::poll($mbox, $uri);
                        logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);
 
                        if (!count($msgs)) {
@@ -1546,7 +1546,7 @@ class Probe
                $data["notify"]  = 'smtp '.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)) {
                        $adr = imap_rfc822_parse_adrlist($x[0]->from, '');
                } elseif (stristr($x[0]->to, $uri)) {
index ceca79cb888e44a638192ba03242988b68022654..c962de725e96b23f7cb95af7211d11632d810085 100644 (file)
@@ -19,7 +19,7 @@ class Email
         * @param string $password The password
         * @return object
         */
-       public static function emailConnect($mailbox, $username, $password)
+       public static function connect($mailbox, $username, $password)
        {
                if (! function_exists('imap_open')) {
                        return false;
@@ -35,7 +35,7 @@ class Email
         * @param string $email_addr email
         * @return array
         */
-       public static function emailPoll($mbox, $email_addr)
+       public static function poll($mbox, $email_addr)
        {
                if (! ($mbox && $email_addr))
                        return array();
@@ -83,44 +83,19 @@ class Email
         * @param integer $uid  user id
         * @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
                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 integer $uid   user id
         * @param string  $reply reply
         * @return array
         */
-       public static function emailGetMsg($mbox, $uid, $reply)
+       public static function getMessage($mbox, $uid, $reply)
        {
                $ret = array();
 
@@ -131,11 +106,11 @@ class Email
                }
 
                if (! $struc->parts) {
-                       $ret['body'] = self::emailGetPart($mbox, $uid, $struc, 0, 'html');
+                       $ret['body'] = self::messageGetPart($mbox, $uid, $struc, 0, 'html');
                        $html = $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 {
                                $ret['body'] = html2bbcode($ret['body']);
                        }
@@ -143,12 +118,12 @@ class Email
                        $text = '';
                        $html = '';
                        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) {
                                        $text .= $x;
                                }
 
-                               $x = self::emailGetPart($mbox, $uid, $p, $ptop + 1, 'html');
+                               $x = self::messageGetPart($mbox, $uid, $p, $ptop + 1, 'html');
                                if ($x) {
                                        $html .= $x;
                                }
@@ -184,7 +159,7 @@ class Email
         * @param string  $subtype sub type
         * @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
                global $htmlmsg,$plainmsg,$charset,$attachments;
@@ -257,7 +232,7 @@ class Email
                if (isset($p->parts) && $p->parts) {
                        $x = "";
                        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) {
                                //      return $x;
                                //}
@@ -271,7 +246,7 @@ class Email
         * @param string $charset character set
         * @return string
         */
-       public static function emailHeaderEncode($in_str, $charset)
+       public static function encodeHeader($in_str, $charset)
        {
                $out_str = $in_str;
                $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)
         *
         * @param string $addr    address
@@ -336,7 +311,7 @@ class Email
         *
         * @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 .= 'Content-Type: text/html; charset=UTF-8' . "\n";
index ec37204000b3b8d0a42f5275037006cb40dfc674..7d4205ac3346ec779a34b90024d9b94a4220dc08 100644 (file)
@@ -37,8 +37,8 @@ class Emailer
                        $email_textonly = PConfig::get($params['uid'], "system", "email_textonly");
                }
 
-               $fromName = Email::emailHeaderEncode(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');
+               $fromName = Email::encodeHeader(html_entity_decode($params['fromName'], ENT_QUOTES, 'UTF-8'), 'UTF-8');
+               $messageSubject = Email::encodeHeader(html_entity_decode($params['messageSubject'], ENT_QUOTES, 'UTF-8'), 'UTF-8');
 
                // generate a mime boundary
                $mimeBoundary   =rand(0, 9)."-"
index 7d800f54f79bdaaabddbee248d12fc751d47c4ea..f17aa5507b8dc1843fe823b53f298f9123728903 100644 (file)
@@ -418,19 +418,19 @@ class Delivery {
                                        if ($r1 && $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
 
                                        if (($contact['rel'] == CONTACT_IS_FRIEND) && !$contact['blocked']) {
                                                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";
                                                } 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 {
-                                               $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)
@@ -469,7 +469,7 @@ class Delivery {
                                                if (strncasecmp($subject,'RE:',3))
                                                        $subject = 'Re: '.$subject;
                                        }
-                                       Email::emailSend($addr, $subject, $headers, $it);
+                                       Email::send($addr, $subject, $headers, $it);
                                }
                                break;
 
index 3f00454b2a385abadb8b75bc9ed26bfcb0d4e474..f7f7bcccf850d0effe6c5f90a118b0f3c6aaccd4 100644 (file)
@@ -331,7 +331,7 @@ Class OnePoll
                                $mailbox = Email::constructMailboxName($mailconf);
                                $password = '';
                                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);
                                logger("Mail: Connect to " . $mailconf['user']);
                                if ($mbox) {
@@ -344,12 +344,12 @@ Class OnePoll
                        }
 
                        if ($mbox) {
-                               $msgs = Email::emailPoll($mbox, $contact['addr']);
+                               $msgs = Email::poll($mbox, $contact['addr']);
 
                                if (count($msgs)) {
                                        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)) {
                                                logger("onepoll: for " . $mailconf['user'] . " there are ". count($msgs) . " messages but received " . count($metas) . " metas", LOGGER_DEBUG);
                                        } else {
@@ -361,8 +361,7 @@ Class OnePoll
                                                        $datarray = array();
                                                        $datarray['verb'] = ACTIVITY_POST;
                                                        $datarray['object-type'] = ACTIVITY_OBJ_NOTE;
-                                                       // $meta = Email::emailMsgMeta($mbox, $msg_uid);
-                                                       // $headers = email_msg_headers($mbox, $msg_uid);
+                                                       // $meta = Email::messageMeta($mbox, $msg_uid);
 
                                                        $datarray['uri'] = Email::msgid2iri(trim($meta->message_id, '<>'));
 
@@ -466,7 +465,7 @@ Class OnePoll
                                                                $datarray['parent-uri'] = $datarray['uri'];
                                                        }
 
-                                                       $r = Email::emailGetMsg($mbox, $msg_uid, $reply);
+                                                       $r = Email::getMessage($mbox, $msg_uid, $reply);
                                                        if (!$r) {
                                                                logger("Mail: can't fetch msg ".$msg_uid." for ".$mailconf['user']);
                                                                continue;