mail changes
This commit is contained in:
parent
c7bcdf0c18
commit
863ddf1676
|
@ -513,7 +513,7 @@ CREATE TABLE IF NOT EXISTS `mailacct` (
|
|||
`ssltype` CHAR( 16 ) NOT NULL,
|
||||
`mailbox` CHAR( 255 ) NOT NULL,
|
||||
`user` CHAR( 255 ) NOT NULL ,
|
||||
`pass` CHAR( 255 ) NOT NULL ,
|
||||
`pass` TEXT NOT NULL ,
|
||||
`reply_to` CHAR( 255 ) NOT NULL ,
|
||||
`last_check` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
|
||||
) ENGINE = MYISAM DEFAULT CHARSET=utf8;
|
||||
|
|
|
@ -264,6 +264,7 @@ function scrape_feed($url) {
|
|||
|
||||
|
||||
function probe_url($url) {
|
||||
require_once('include/email.php');
|
||||
|
||||
$result = array();
|
||||
|
||||
|
@ -313,8 +314,38 @@ function probe_url($url) {
|
|||
}
|
||||
}
|
||||
else {
|
||||
|
||||
// Check email
|
||||
|
||||
$orig_url = $url;
|
||||
if((strpos($orig_url,'@')) && validate_email($orig_url)) {
|
||||
$email_conversant = true;
|
||||
$x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1",
|
||||
intval(local_user())
|
||||
);
|
||||
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
|
||||
intval(local_user())
|
||||
);
|
||||
if(count($x) && count($r)) {
|
||||
$mailbox = construct_mailbox_name($r[0]);
|
||||
$password = '';
|
||||
openssl_private_decrypt(hex2bin($r[0]['pass']),$password,$x[0]['prvkey']);
|
||||
$mbox = email_connect($mailbox,$r[0]['user'],$password);
|
||||
unset($password);
|
||||
}
|
||||
if($mbox) {
|
||||
$msgs = email_poll($mbox,$orig_url);
|
||||
if(count($msgs)) {
|
||||
$addr = $orig_url;
|
||||
$network = NETWORK_MAIL;
|
||||
$name = substr($url,0,strpos($url,'@'));
|
||||
// fix nick
|
||||
$vcard = array('fn' => $name, 'nick' => $name, 'photo' => gravatar_img($url));
|
||||
$notify = 'smtp';
|
||||
$poll = 'email';
|
||||
$priority = 0;
|
||||
}
|
||||
imap_close($mbox);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -330,7 +361,7 @@ function probe_url($url) {
|
|||
}
|
||||
}
|
||||
|
||||
if($network !== NETWORK_DFRN) {
|
||||
if($network !== NETWORK_DFRN && $network !== NETWORK_MAIL) {
|
||||
$network = NETWORK_OSTATUS;
|
||||
$priority = 0;
|
||||
|
||||
|
@ -435,9 +466,11 @@ function probe_url($url) {
|
|||
$vcard['fn'] = notags($vcard['fn']);
|
||||
$vcard['nick'] = notags($vcard['nick']);
|
||||
|
||||
|
||||
$result['name'] = $vcard['fn'];
|
||||
$result['nick'] = $vcard['nick'];
|
||||
$result['url'] = $profile;
|
||||
$result['addr'] = $addr;
|
||||
$result['notify'] = $notify;
|
||||
$result['poll'] = $poll;
|
||||
$result['request'] = $request;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
function email_connect($mailbox,$username,$password) {
|
||||
if(! (local_user() && function_exists('imap_open')))
|
||||
if(! function_exists('imap_open'))
|
||||
return false;
|
||||
|
||||
$mbox = imap_open($mailbox,$username,$password);
|
||||
|
@ -33,36 +33,41 @@ function email_msg_meta($mbox,$uid) {
|
|||
}
|
||||
|
||||
|
||||
function email_get_msg($mbox,$uid) {
|
||||
$ret = array();
|
||||
|
||||
function getmsg($mbox,$mid) {
|
||||
// input $mbox = IMAP stream, $mid = message id
|
||||
// output all the following:
|
||||
global $charset,$htmlmsg,$plainmsg,$attachments;
|
||||
$htmlmsg = $plainmsg = $charset = '';
|
||||
$attachments = array();
|
||||
$struc = (($mbox && $uid) ? imap_fetchstructure($mbox,$uid,FT_UID) : null);
|
||||
|
||||
// HEADER
|
||||
$h = imap_header($mbox,$mid);
|
||||
// add code here to get date, from, to, cc, subject...
|
||||
if(! $struc)
|
||||
return $ret;
|
||||
|
||||
// BODY
|
||||
$s = imap_fetchstructure($mbox,$mid);
|
||||
if (!$s->parts) // simple
|
||||
getpart($mbox,$mid,$s,0); // pass 0 as part-number
|
||||
else { // multipart: cycle through each part
|
||||
foreach ($s->parts as $partno0=>$p)
|
||||
getpart($mbox,$mid,$p,$partno0+1);
|
||||
if(! $struc->parts) {
|
||||
$ret['body'] = email_get_part($mbox,$uid,$struc,0);
|
||||
}
|
||||
else {
|
||||
foreach($struc->parts as $ptop => $p) {
|
||||
$x = email_get_part($mbox,$uid,$p,$ptop + 1);
|
||||
if($x)
|
||||
$ret['body'] = $x;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function getpart($mbox,$mid,$p,$partno) {
|
||||
// At the moment - only return plain/text.
|
||||
// Later we'll repackage inline images as data url's and make the HTML safe
|
||||
|
||||
function email_get_part($mbox,$uid,$p,$partno) {
|
||||
// $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple
|
||||
global $htmlmsg,$plainmsg,$charset,$attachments;
|
||||
|
||||
echo $partno;
|
||||
|
||||
// DECODE DATA
|
||||
$data = ($partno)?
|
||||
imap_fetchbody($mbox,$mid,$partno): // multipart
|
||||
imap_body($mbox,$mid); // simple
|
||||
$data = ($partno)
|
||||
? imap_fetchbody($mbox,$uid,$partno, FT_UID|FT_PEEK)
|
||||
: imap_body($mbox,$uid,FT_UID|FT_PEEK);
|
||||
|
||||
// Any part may be encoded, even plain text messages, so check everything.
|
||||
if ($p->encoding==4)
|
||||
$data = quoted_printable_decode($data);
|
||||
|
@ -82,6 +87,7 @@ function getpart($mbox,$mid,$p,$partno) {
|
|||
// ATTACHMENT
|
||||
// Any part with a filename is an attachment,
|
||||
// so an attached text file (type 0) is not mistaken as the message.
|
||||
|
||||
if ($params['filename'] || $params['name']) {
|
||||
// filename may be given as 'Filename' or 'Name' or both
|
||||
$filename = ($params['filename'])? $params['filename'] : $params['name'];
|
||||
|
@ -94,9 +100,11 @@ function getpart($mbox,$mid,$p,$partno) {
|
|||
// Messages may be split in different parts because of inline attachments,
|
||||
// so append parts together with blank row.
|
||||
if (strtolower($p->subtype)=='plain')
|
||||
$plainmsg .= trim($data) ."\n\n";
|
||||
return (trim($data) ."\n\n");
|
||||
else
|
||||
$htmlmsg .= $data ."<br><br>";
|
||||
$data = '';
|
||||
|
||||
// $htmlmsg .= $data ."<br><br>";
|
||||
$charset = $params['charset']; // assume all parts are same charset
|
||||
}
|
||||
|
||||
|
@ -105,13 +113,19 @@ function getpart($mbox,$mid,$p,$partno) {
|
|||
// but AOL uses type 1 (multipart), which is not handled here.
|
||||
// There are no PHP functions to parse embedded messages,
|
||||
// so this just appends the raw source to the main message.
|
||||
elseif ($p->type==2 && $data) {
|
||||
$plainmsg .= $data."\n\n";
|
||||
}
|
||||
// elseif ($p->type==2 && $data) {
|
||||
// $plainmsg .= $data."\n\n";
|
||||
// }
|
||||
|
||||
// SUBPART RECURSION
|
||||
if ($p->parts) {
|
||||
foreach ($p->parts as $partno0=>$p2)
|
||||
getpart($mbox,$mid,$p2,$partno.'.'.($partno0+1)); // 1.2, 1.2.1, etc.
|
||||
foreach ($p->parts as $partno0=>$p2) {
|
||||
$x = email_get_part($mbox,$uid,$p2,$partno . '.' . ($partno0+1)); // 1.2, 1.2.1, etc.
|
||||
if($x)
|
||||
return $x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -289,7 +289,7 @@ function poller_run($argv, $argc){
|
|||
}
|
||||
elseif($contact['network'] === NETWORK_MAIL) {
|
||||
if(! $mbox) {
|
||||
$x = q("SELECT `prvkey` FROM `user` WHERE `uid` = $d LIMIT 1",
|
||||
$x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1",
|
||||
intval($importer_uid)
|
||||
);
|
||||
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
|
||||
|
@ -298,7 +298,7 @@ function poller_run($argv, $argc){
|
|||
if(count($x) && count($r)) {
|
||||
$mailbox = construct_mailbox_name($r[0]);
|
||||
$password = '';
|
||||
openssl_private_decrypt($r[0]['pass'],$password,$x[0]['prvkey']);
|
||||
openssl_private_decrypt(hex2bin($r[0]['pass']),$password,$x[0]['prvkey']);
|
||||
$mbox = email_connect($mailbox,$r[0]['user'],$password);
|
||||
unset($password);
|
||||
}
|
||||
|
@ -306,7 +306,42 @@ function poller_run($argv, $argc){
|
|||
if($mbox) {
|
||||
$msgs = email_poll($mbox,$contact['addr']);
|
||||
if(count($msgs)) {
|
||||
// TODO: loop through, fetch, check duplicates, and import
|
||||
foreach($msgs as $msg_uid) {
|
||||
$datarray = array();
|
||||
$meta = email_msg_meta($mbox,$msg_uid);
|
||||
$datarray['uri'] = trim($meta->message_id,'<>');
|
||||
//FIXME
|
||||
$datarray['parent-uri'] = $datarray['uri'];
|
||||
// Have we seen it before?
|
||||
$r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
|
||||
intval($importer_uid),
|
||||
dbesc($datarray['uri'])
|
||||
);
|
||||
if(count($r)) {
|
||||
if($meta->deleted && ! $r[0]['deleted']) {
|
||||
q("UPDATE `item` SET `deleted` = `, `changed` = '%s' WHERE `id` = %d LIMIT 1",
|
||||
dbesc(datetime_convert()),
|
||||
intval($r[0]['id'])
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$datarray['title'] = notags(trim($meta->subject));
|
||||
$datarray['created'] = datetime_convert('UTC','UTC',$meta->date);
|
||||
|
||||
$r = email_get_msg($mbox,$msg_uid);
|
||||
if(! $r)
|
||||
continue;
|
||||
$datarray['body'] = escape_tags($r['body']);
|
||||
$datarray['uid'] = $importer_uid;
|
||||
$datarray['contact-id'] = $contact['id'];
|
||||
$datarray['private'] = 1;
|
||||
$datarray['author-name'] = $contact['name'];
|
||||
$datarray['author-link'] = 'mailbox';
|
||||
$datarray['author-avatar'] = $contact['photo'];
|
||||
|
||||
item_store($datarray);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -360,6 +395,9 @@ function poller_run($argv, $argc){
|
|||
}
|
||||
}
|
||||
|
||||
if($mbox && function_exists('imap_close'))
|
||||
imap_close($mbox);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ function follow_post(&$a) {
|
|||
|
||||
// do we have enough information?
|
||||
|
||||
if(! ((x($ret,'name')) && (x($ret,'poll')) && (x($ret,'url')))) {
|
||||
if(! ((x($ret,'name')) && (x($ret,'poll')) && ((x($ret,'url')) || (x($ret,'addr'))))) {
|
||||
notice( t('The profile address specified does not provide adequate information.') . EOL);
|
||||
goaway($_SESSION['return_url']);
|
||||
}
|
||||
|
@ -39,7 +39,10 @@ function follow_post(&$a) {
|
|||
}
|
||||
|
||||
$writeable = ((($ret['network'] === NETWORK_OSTATUS) && ($ret['notify'])) ? 1 : 0);
|
||||
if($ret['network'] === NETWORK_MAIL) {
|
||||
$writeable = 1;
|
||||
|
||||
}
|
||||
// check if we already have a contact
|
||||
// the poll url is more reliable than the profile url, as we may have
|
||||
// indirect links or webfinger links
|
||||
|
@ -61,12 +64,13 @@ function follow_post(&$a) {
|
|||
}
|
||||
else {
|
||||
// create contact record
|
||||
$r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`,
|
||||
$r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`,
|
||||
`writable`, `blocked`, `readonly`, `pending` )
|
||||
VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ",
|
||||
VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ",
|
||||
intval(local_user()),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($ret['url']),
|
||||
dbesc($ret['addr']),
|
||||
dbesc($ret['alias']),
|
||||
dbesc($ret['notify']),
|
||||
dbesc($ret['poll']),
|
||||
|
@ -74,9 +78,9 @@ function follow_post(&$a) {
|
|||
dbesc($ret['nick']),
|
||||
dbesc($ret['photo']),
|
||||
dbesc($ret['network']),
|
||||
intval(REL_FAN),
|
||||
intval(($ret['network'] === NETWORK_MAIL) ? REL_BUD : REL_FAN),
|
||||
intval($ret['priority']),
|
||||
intval($writable)
|
||||
intval($writeable)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -469,3 +469,8 @@ function update_1051() {
|
|||
q("ALTER TABLE `contact` ADD `addr` CHAR( 255 ) NOT NULL AFTER `url` ");
|
||||
}
|
||||
|
||||
function update_1052() {
|
||||
q("ALTER TABLE `mailacct` CHANGE `pass` `pass` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue