aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorFriendika <info@friendika.com>2011-04-16 08:45:08 -0700
committerFriendika <info@friendika.com>2011-04-16 08:45:08 -0700
commit863ddf1676be3837da4219ed7883e61e4d493b1c (patch)
treefacfdd413c2050259bd656d2f608e8449286f389 /include
parentc7bcdf0c186c8d5ce278a3710a5ba570d066be99 (diff)
downloadvolse-hubzilla-863ddf1676be3837da4219ed7883e61e4d493b1c.tar.gz
volse-hubzilla-863ddf1676be3837da4219ed7883e61e4d493b1c.tar.bz2
volse-hubzilla-863ddf1676be3837da4219ed7883e61e4d493b1c.zip
mail changes
Diffstat (limited to 'include')
-rw-r--r--include/Scrape.php37
-rw-r--r--include/email.php76
-rw-r--r--include/poller.php44
3 files changed, 121 insertions, 36 deletions
diff --git a/include/Scrape.php b/include/Scrape.php
index e5c10a9be..97e2fb7f1 100644
--- a/include/Scrape.php
+++ b/include/Scrape.php
@@ -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;
diff --git a/include/email.php b/include/email.php
index 4d8c25edf..c0fe17cc6 100644
--- a/include/email.php
+++ b/include/email.php
@@ -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'];
@@ -90,13 +96,15 @@ function getpart($mbox,$mid,$p,$partno) {
}
// TEXT
- if ($p->type==0 && $data) {
+ if ($p->type == 0 && $data) {
// 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;
+ }
}
-} \ No newline at end of file
+}
+
+
+
diff --git a/include/poller.php b/include/poller.php
index 37109f17d..b8bd0b708 100644
--- a/include/poller.php
+++ b/include/poller.php
@@ -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);
+ }
}
}
}
@@ -359,6 +394,9 @@ function poller_run($argv, $argc){
// loop - next contact
}
}
+
+ if($mbox && function_exists('imap_close'))
+ imap_close($mbox);
return;
}