X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Femail.php;h=78e98a830c3dec87e1c2d9e5fc81dd2b59da11cd;hb=0cd9db9cb7f4c96f597e37590a536eaae123238d;hp=b43ae0dc1c200614a94e4beef83a04b543f65b99;hpb=7d23149a61f75923b2c71a288a722ee219f5e6ba;p=friendica.git diff --git a/include/email.php b/include/email.php old mode 100755 new mode 100644 index b43ae0dc1c..78e98a830c --- a/include/email.php +++ b/include/email.php @@ -4,7 +4,7 @@ require_once('include/msgclean.php'); require_once('include/quoteconvert.php'); function email_connect($mailbox,$username,$password) { - if(! function_exists('imap_open')) + if (! function_exists('imap_open')) return false; $mbox = @imap_open($mailbox,$username,$password); @@ -14,23 +14,23 @@ function email_connect($mailbox,$username,$password) { function email_poll($mbox,$email_addr) { - if(! ($mbox && $email_addr)) + if (! ($mbox && $email_addr)) return array(); $search1 = @imap_search($mbox,'FROM "' . $email_addr . '"', SE_UID); - if(! $search1) + if (! $search1) $search1 = array(); $search2 = @imap_search($mbox,'TO "' . $email_addr . '"', SE_UID); - if(! $search2) + if (! $search2) $search2 = array(); $search3 = @imap_search($mbox,'CC "' . $email_addr . '"', SE_UID); - if(! $search3) + if (! $search3) $search3 = array(); $search4 = @imap_search($mbox,'BCC "' . $email_addr . '"', SE_UID); - if(! $search4) + if (! $search4) $search4 = array(); $res = array_unique(array_merge($search1,$search2,$search3,$search4)); @@ -48,8 +48,8 @@ function construct_mailbox_name($mailacct) { function email_msg_meta($mbox,$uid) { - $ret = (($mbox && $uid) ? @imap_fetch_overview($mbox,$uid,FT_UID) : array(array())); - return ((count($ret)) ? $ret[0] : array()); + $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()); } function email_msg_headers($mbox,$uid) { @@ -57,8 +57,8 @@ function email_msg_headers($mbox,$uid) { $raw_header = str_replace("\r",'',$raw_header); $ret = array(); $h = explode("\n",$raw_header); - if(count($h)) - foreach($h as $line ) { + 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); @@ -79,14 +79,10 @@ function email_get_msg($mbox,$uid, $reply) { $struc = (($mbox && $uid) ? @imap_fetchstructure($mbox,$uid,FT_UID) : null); - if(! $struc) + if (! $struc) return $ret; - // for testing purposes: Collect imported mails - // $file = tempnam("/tmp/friendica2/", "mail-in-"); - // file_put_contents($file, json_encode($struc)); - - if(! $struc->parts) { + if (! $struc->parts) { $ret['body'] = email_get_part($mbox,$uid,$struc,0, 'html'); $html = $ret['body']; @@ -98,17 +94,22 @@ function email_get_msg($mbox,$uid, $reply) { else { $text = ''; $html = ''; - foreach($struc->parts as $ptop => $p) { + foreach ($struc->parts as $ptop => $p) { $x = email_get_part($mbox,$uid,$p,$ptop + 1, 'plain'); - if($x) $text .= $x; + if ($x) { + $text .= $x; + } $x = email_get_part($mbox,$uid,$p,$ptop + 1, 'html'); - if($x) $html .= $x; + if ($x) { + $html .= $x; + } } - if (trim($html) != '') + if (trim($html) != '') { $ret['body'] = html2bbcode($html); - else + } else { $ret['body'] = $text; + } } $ret['body'] = removegpg($ret['body']); @@ -116,8 +117,9 @@ function email_get_msg($mbox,$uid, $reply) { $ret['body'] = $msg['body']; $ret['body'] = convertquote($ret['body'], $reply); - if (trim($html) != '') + if (trim($html) != '') { $ret['body'] = removelinebreak($ret['body']); + } $ret['body'] = unifyattributionline($ret['body']); @@ -138,10 +140,6 @@ function email_get_part($mbox,$uid,$p,$partno, $subtype) { ? @imap_fetchbody($mbox,$uid,$partno, FT_UID|FT_PEEK) : @imap_body($mbox,$uid,FT_UID|FT_PEEK); - // for testing purposes: Collect imported mails - // $file = tempnam("/tmp/friendica2/", "mail-body-"); - // file_put_contents($file, $data); - // Any part may be encoded, even plain text messages, so check everything. if ($p->encoding==4) $data = quoted_printable_decode($data); @@ -154,7 +152,7 @@ function email_get_part($mbox,$uid,$p,$partno, $subtype) { if ($p->parameters) foreach ($p->parameters as $x) $params[strtolower($x->attribute)] = $x->value; - if (isset($p->dparameters) and $p->dparameters) + if (isset($p->dparameters) && $p->dparameters) foreach ($p->dparameters as $x) $params[strtolower($x->attribute)] = $x->value; @@ -162,7 +160,7 @@ function email_get_part($mbox,$uid,$p,$partno, $subtype) { // Any part with a filename is an attachment, // so an attached text file (type 0) is not mistaken as the message. - if ((isset($params['filename']) and $params['filename']) || (isset($params['name']) and $params['name'])) { + if ((isset($params['filename']) && $params['filename']) || (isset($params['name']) && $params['name'])) { // filename may be given as 'Filename' or 'Name' or both $filename = ($params['filename'])? $params['filename'] : $params['name']; // filename may be encoded, so see imap_mime_header_decode() @@ -193,12 +191,13 @@ function email_get_part($mbox,$uid,$p,$partno, $subtype) { // } // SUBPART RECURSION - if (isset($p->parts) and $p->parts) { + if (isset($p->parts) && $p->parts) { $x = ""; foreach ($p->parts as $partno0=>$p2) { $x .= email_get_part($mbox,$uid,$p2,$partno . '.' . ($partno0+1), $subtype); // 1.2, 1.2.1, etc. - //if($x) + //if ($x) { // return $x; + //} } return $x; } @@ -207,16 +206,16 @@ function email_get_part($mbox,$uid,$p,$partno, $subtype) { function email_header_encode($in_str, $charset) { - $out_str = $in_str; + $out_str = $in_str; $need_to_convert = false; - for($x = 0; $x < strlen($in_str); $x ++) { - if((ord($in_str[$x]) == 0) || ((ord($in_str[$x]) > 128))) { + for ($x = 0; $x < strlen($in_str); $x ++) { + if ((ord($in_str[$x]) == 0) || ((ord($in_str[$x]) > 128))) { $need_to_convert = true; } } - if(! $need_to_convert) + if (! $need_to_convert) return $in_str; if ($out_str && $charset) { @@ -257,6 +256,12 @@ function email_header_encode($in_str, $charset) { return $out_str; } +/** + * email_send is used by NETWORK_EMAIL and NETWORK_EMAIL2 code + * (not to notify the user, but to send items to email contacts) + * + * @todo This could be changed to use the Emailer class + */ function email_send($addr, $subject, $headers, $item) { //$headers .= 'MIME-Version: 1.0' . "\n"; //$headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";