Merge branch 'imap'

This commit is contained in:
Friendika 2011-04-17 23:28:39 -07:00
commit 229eb9c681
19 changed files with 571 additions and 69 deletions

View file

@ -4,7 +4,7 @@ set_time_limit(0);
define ( 'FRIENDIKA_VERSION', '2.1.951' );
define ( 'DFRN_PROTOCOL_VERSION', '2.21' );
define ( 'DB_UPDATE_VERSION', 1052 );
define ( 'DB_UPDATE_VERSION', 1053 );
define ( 'EOL', "<br />\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );

View file

@ -195,6 +195,7 @@ CREATE TABLE IF NOT EXISTS `item` (
`deny_cid` mediumtext NOT NULL,
`deny_gid` mediumtext NOT NULL,
`private` tinyint(1) NOT NULL DEFAULT '0',
`pubmail` tinyint(1) NOT NULL DEFAULT '0',
`visible` tinyint(1) NOT NULL DEFAULT '0',
`unseen` tinyint(1) NOT NULL DEFAULT '1',
`deleted` tinyint(1) NOT NULL DEFAULT '0',
@ -513,8 +514,9 @@ 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 ,
`pubmail` TINYINT(1) NOT NULL DEFAULT '0',
`last_check` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE = MYISAM DEFAULT CHARSET=utf8;

View file

@ -264,6 +264,7 @@ function scrape_feed($url) {
function probe_url($url) {
require_once('include/email.php');
$result = array();
@ -313,8 +314,43 @@ 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 AND `server` != '' 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,'@'));
$profile = 'http://' . substr($url,strpos($url,'@')+1);
// fix nick character range
$vcard = array('fn' => $name, 'nick' => $name, 'photo' => gravatar_img($url));
$notify = 'smtp ' . random_string();
$poll = 'email ' . random_string();
$priority = 0;
$x = email_msg_meta($mbox,$msgs[0]);
$adr = imap_rfc822_parse_adrlist($x->from,'');
if(strlen($adr[0]->personal))
$vcard['fn'] = notags($adr[0]->personal);
}
imap_close($mbox);
}
}
}
}
@ -330,7 +366,7 @@ function probe_url($url) {
}
}
if($network !== NETWORK_DFRN) {
if($network !== NETWORK_DFRN && $network !== NETWORK_MAIL) {
$network = NETWORK_OSTATUS;
$priority = 0;
@ -435,9 +471,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;

View file

@ -85,6 +85,8 @@ function conversation(&$a, $items, $mode, $update) {
$profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
$profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
$profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
if($profile_link === 'mailbox')
$profile_link = '';
$redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
@ -360,6 +362,9 @@ function conversation(&$a, $items, $mode, $update) {
else
$profile_link = $item['url'];
if($profile_link === 'mailbox')
$profile_link = '';
$like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
$dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
@ -483,6 +488,9 @@ function item_photo_menu($item){
$profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
$redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
if($profile_link === 'mailbox')
$profile_link = '';
// $item['contact-uid'] is only set on profile page and indicates the uid of the user who owns the profile.
$profile_owner = ((x($item,'contact-uid')) && intval($item['contact-uid']) ? intval($item['contact-uid']) : 0);
@ -503,6 +511,8 @@ function item_photo_menu($item){
$redir = $a->get_baseurl() . '/redir/' . $a->authors[$item['author-link']]['id'];
$cid = $a->authors[$item['author-link']]['id'];
}
if($item['author-link'] === 'mailbox')
$cid = $item['cid'];
if((isset($cid)) && (! $item['self'])) {
$contact_url = $a->get_baseurl() . '/contacts/' . $cid;

View file

@ -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);
@ -32,37 +32,63 @@ function email_msg_meta($mbox,$uid) {
return ((count($ret)) ? $ret[0] : array());
}
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 = split("\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);
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();
// HEADER
$h = imap_header($mbox,$mid);
// add code here to get date, from, to, cc, subject...
// 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);
$last_entry = strtolower($key);
$ret[$last_entry] = trim($value);
}
else {
$ret[$last_entry] .= ' ' . trim($line);
}
}
return $ret;
}
function getpart($mbox,$mid,$p,$partno) {
function email_get_msg($mbox,$uid) {
$ret = array();
$struc = (($mbox && $uid) ? imap_fetchstructure($mbox,$uid,FT_UID) : null);
if(! $struc)
return $ret;
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;
}
// 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 +108,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 +117,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 +134,58 @@ 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;
}
}
}
function email_header_encode($in_str, $charset) {
$out_str = $in_str;
if ($out_str && $charset) {
// define start delimimter, end delimiter and spacer
$end = "?=";
$start = "=?" . $charset . "?B?";
$spacer = $end . "\r\n " . $start;
// determine length of encoded text within chunks
// and ensure length is even
$length = 75 - strlen($start) - strlen($end);
/*
[EDIT BY danbrown AT php DOT net: The following
is a bugfix provided by (gardan AT gmx DOT de)
on 31-MAR-2005 with the following note:
"This means: $length should not be even,
but divisible by 4. The reason is that in
base64-encoding 3 8-bit-chars are represented
by 4 6-bit-chars. These 4 chars must not be
split between two encoded words, according
to RFC-2047.
*/
$length = $length - ($length % 4);
// encode the string and split it into chunks
// with spacers after each chunk
$out_str = base64_encode($out_str);
$out_str = chunk_split($out_str, $length, $spacer);
// remove trailing spacer and
// add start and end delimiters
$spacer = preg_quote($spacer);
$out_str = preg_replace("/" . $spacer . "$/", "", $out_str);
$out_str = $start . $out_str . $end;
}
return $out_str;
}

View file

@ -123,7 +123,8 @@ function group_public_members($gid) {
if(intval($gid)) {
$r = q("SELECT `contact`.`id` AS `contact-id` FROM `group_member`
LEFT JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id`
WHERE `gid` = %d AND `group_member`.`uid` = %d AND `contact`.`network` != 'dfrn' ",
WHERE `gid` = %d AND `group_member`.`uid` = %d
AND `contact`.`network` != 'dfrn' AND `contact`.`network` != 'mail' ",
intval($gid),
intval(local_user())
);

View file

@ -72,7 +72,7 @@ function notifier_run($argv, $argc){
else {
// find ancestors
$r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
$r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
intval($item_id)
);
@ -80,6 +80,7 @@ function notifier_run($argv, $argc){
return;
}
$parent_item = $r[0];
$parent_id = intval($r[0]['parent']);
$uid = $r[0]['uid'];
$updated = $r[0]['edited'];
@ -267,12 +268,25 @@ function notifier_run($argv, $argc){
logger('notifier: slaps: ' . print_r($slaps,true), LOGGER_DATA);
// If this is a public message and pubmail is set on the parent, include all your email contacts
if((! strlen($parent_item['allow_cid'])) && (! strlen($parent_item['allow_gid'])) && (! strlen($parent_item['deny_cid'])) && (! strlen($parent_item['deny_gid']))
&& (intval($parent_item['pubmail']))) {
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `network` = '%s'",
intval($uid),
dbesc(NETWORK_MAIL)
);
if(count($r)) {
foreach($r as $rr)
$recipients[] = $rr['id'];
}
}
if($followup)
$recip_str = $parent['contact-id'];
else
$recip_str = implode(', ', $recipients);
$r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 AND `pending` = 0 ",
dbesc($recip_str)
);
@ -352,6 +366,79 @@ function notifier_run($argv, $argc){
}
break;
case 'mail':
// WARNING: does not currently convert to RFC2047 header encodings, etc.
$addr = $contact['addr'];
if(! strlen($addr))
break;
if($cmd === 'wall-new' || $cmd === 'comment-new') {
$it = null;
if($cmd === 'wall-new')
$it = $items[0];
else {
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($argv[2]),
intval($uid)
);
if(count($r))
$it = $r[0];
}
if(! $it)
break;
$local_user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($uid)
);
if(! count($local_user))
break;
$reply_to = '';
$r1 = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
intval($uid)
);
if($r1 && $r1[0]['reply_to'])
$reply_to = $r1[0]['reply_to'];
$subject = (($it['title']) ? $it['title'] : t("\x28no subject\x29")) ;
$headers = 'From: ' . $local_user[0]['username'] . ' <' . $local_user[0]['email'] . '>' . "\n";
if($reply_to)
$headers .= 'Reply-to: ' . $reply_to . "\n";
$headers .= 'Message-id: <' . $it['uri'] . '>' . "\n";
if($it['uri'] !== $it['parent-uri']) {
$header .= 'References: <' . $it['parent-uri'] . '>' . "\n";
if(! strlen($it['title'])) {
$r = q("SELECT `title` FROM `item` WHERE `parent-uri` = '%s' LIMIT 1",
dbesc($it['parent-uri'])
);
if(count($r)) {
$subtitle = $r[0]['title'];
if($subtitle) {
if(strncasecmp($subtitle,'RE:',3))
$subject = $subtitle;
else
$subject = 'Re: ' . $subtitle;
}
}
}
}
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
$headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n";
$html = prepare_body($it);
$message = '<html><body>' . $html . '</body></html>';
logger('notifier: email delivery to ' . $addr);
mail($addr, $subject, $message, $headers);
}
break;
case 'dspr':
case 'feed':
case 'face':

View file

@ -289,24 +289,99 @@ 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",
$mailconf = q("SELECT * FROM `mailacct` WHERE `server` != '' AND `uid` = %d LIMIT 1",
intval($importer_uid)
);
if(count($x) && count($r)) {
$mailbox = construct_mailbox_name($r[0]);
if(count($x) && count($mailconf)) {
$mailbox = construct_mailbox_name($mailconf[0]);
$password = '';
openssl_private_decrypt($r[0]['pass'],$password,$x[0]['prvkey']);
$mbox = email_connect($mailbox,$r[0]['user'],$password);
openssl_private_decrypt(hex2bin($mailconf[0]['pass']),$password,$x[0]['prvkey']);
$mbox = email_connect($mailbox,$mailconf[0]['user'],$password);
unset($password);
if($mbox) {
q("UPDATE `mailacct` SET `last_check` = '%d' WHERE `id` = %d AND `uid` = %d LIMIT 1",
dbesc(datetime_convert()),
intval($mailconf[0]['id']),
intval($importer_uid)
);
}
}
}
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);
$headers = email_msg_headers($mbox,$msg_uid);
// look for a 'references' header and try and match with a parent item we have locally.
$raw_refs = ((x($headers,'references')) ? str_replace("\t",'',$headers['references']) : '');
$datarray['uri'] = trim($meta->message_id,'<>');
if($raw_refs) {
$refs_arr = explode(' ', $raw_refs);
if(count($refs_arr)) {
for($x = 0; $x < count($refs_arr); $x ++)
$refs_arr[$x] = "'" . str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x])) . "'";
}
$qstr = implode(',',$refs_arr);
$r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `uri` IN ( $qstr ) AND `uid` = %d LIMIT 1",
intval($importer_uid)
);
if(count($r))
$datarray['parent-uri'] = $r[0]['uri'];
}
if(! x($datarray,'parent-uri'))
$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'];
if($datarray['parent-uri'] === $datarray['uri'])
$datarray['private'] = 1;
$datarray['author-name'] = $contact['name'];
$datarray['author-link'] = 'mailbox';
$datarray['author-avatar'] = $contact['photo'];
$stored_item = item_store($datarray);
q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d",
dbesc($datarray['parent-uri']),
intval($importer_uid)
);
q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1",
intval($stored_item)
);
}
}
}
}
@ -360,6 +435,9 @@ function poller_run($argv, $argc){
}
}
if($mbox && function_exists('imap_close'))
imap_close($mbox);
return;
}

View file

@ -284,7 +284,7 @@ function contacts_content(&$a) {
'$contact_id' => $r[0]['id'],
'$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
'$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
'$insecure' => (($r[0]['network'] !== 'dfrn') ? $insecure : ''),
'$insecure' => (($r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_MAIL) ? $insecure : ''),
'$info' => $r[0]['info'],
'$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
'$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),

View file

@ -51,6 +51,28 @@ function editpost_content(&$a) {
$jotplugins = '';
$jotnets = '';
$mail_enabled = false;
$pubmail_enabled = false;
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
intval(local_user())
);
if(count($r)) {
$mail_enabled = true;
if(intval($r[0]['pubmail']))
$pubmail_enabled = true;
}
if($mail_enabled) {
$selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
$jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . 'value="1" /> '
. t("Post to Email") . '</div>';
}
call_hooks('jot_tool', $jotplugins);
call_hooks('jot_networks', $jotnets);

View file

@ -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)
);
}

View file

@ -96,6 +96,7 @@ function item_post(&$a) {
$body = escape_tags(trim($_POST['body']));
$private = $orig_post['private'];
$pubmail_enable = $orig_post['pubmail'];
}
else {
$str_group_allow = perms2str($_POST['group_allow']);
@ -121,6 +122,7 @@ function item_post(&$a) {
$private = 1;
}
$pubmail_enable = ((x($_POST,'pubmail_enable') && intval($_POST['pubmail_enable']) && (! $private)) ? 1 : 0);
if(! strlen($body)) {
notice( t('Empty post discarded.') . EOL );
@ -362,6 +364,7 @@ function item_post(&$a) {
$datarray['deny_cid'] = $str_contact_deny;
$datarray['deny_gid'] = $str_group_deny;
$datarray['private'] = $private;
$datarray['pubmail'] = $pubmail_enable;
/**
* These fields are for the convenience of plugins...
@ -399,8 +402,8 @@ function item_post(&$a) {
$r = q("INSERT INTO `item` (`uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`,
`author-name`, `author-link`, `author-avatar`, `created`, `edited`, `changed`, `uri`, `title`, `body`, `location`, `coord`,
`tag`, `inform`, `verb`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private` )
VALUES( %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d )",
`tag`, `inform`, `verb`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail` )
VALUES( %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
intval($datarray['uid']),
dbesc($datarray['type']),
intval($datarray['wall']),
@ -427,7 +430,8 @@ function item_post(&$a) {
dbesc($datarray['allow_gid']),
dbesc($datarray['deny_cid']),
dbesc($datarray['deny_gid']),
intval($datarray['private'])
intval($datarray['private']),
intval($datarray['pubmail'])
);
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
@ -545,11 +549,10 @@ function item_post(&$a) {
$addr = trim($recip);
if(! strlen($addr))
continue;
$disclaimer = '<hr />' . sprintf(t('This message was sent to you by %s, a member of the Friendika social network.'),$a->user['username'])
$disclaimer = '<hr />' . sprintf( t('This message was sent to you by %s, a member of the Friendika social network.'),$a->user['username'])
. '<br />';
$disclaimer .= t('You may visit them online at') . ' '
. $a->get_baseurl() . '/profile/' . $a->user['nickname'] . '<br />';
$disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . '<br />';
$disclaimer .= sprintf( t('You may visit them online at %s'), $a->get_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;
$subject = '[Friendika]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']);
$headers = 'From: ' . $a->user['username'] . ' <' . $a->user['email'] . '>' . "\n";

View file

@ -94,6 +94,28 @@ function network_content(&$a, $update = 0) {
$jotplugins = '';
$jotnets = '';
$mail_enabled = false;
$pubmail_enabled = false;
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
intval(local_user())
);
if(count($r)) {
$mail_enabled = true;
if(intval($r[0]['pubmail']))
$pubmail_enabled = true;
}
if($mail_enabled) {
$selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
$jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . 'value="1" /> '
. t("Post to Email") . '</div>';
}
call_hooks('jot_tool', $jotplugins);
call_hooks('jot_networks', $jotnets);

View file

@ -147,6 +147,26 @@ function profile_content(&$a, $update = 0) {
$jotplugins = '';
$jotnets = '';
$mail_enabled = false;
$pubmail_enabled = false;
if($is_owner) {
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
intval(local_user())
);
if(count($r)) {
$mail_enabled = true;
if(intval($r[0]['pubmail']))
$pubmail_enabled = true;
}
}
if($mail_enabled) {
$selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
$jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . 'value="1" /> '
. t("Post to Email") . '</div>';
}
call_hooks('jot_tool', $jotplugins);
call_hooks('jot_networks', $jotnets);

View file

@ -73,6 +73,41 @@ function settings_post(&$a) {
$page_flags = (((x($_POST,'page-flags')) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0);
$blockwall = (((x($_POST,'blockwall')) && (intval($_POST['blockwall']) == 1)) ? 0: 1); // this setting is inverted!
$mail_server = ((x($_POST,'mail_server')) ? $_POST['mail_server'] : '');
$mail_port = ((x($_POST,'mail_port')) ? $_POST['mail_port'] : '');
$mail_ssl = ((x($_POST,'mail_ssl')) ? strtolower(trim($_POST['mail_ssl'])) : '');
$mail_user = ((x($_POST,'mail_user')) ? $_POST['mail_user'] : '');
$mail_pass = ((x($_POST,'mail_pass')) ? trim($_POST['mail_pass']) : '');
$mail_replyto = ((x($_POST,'mail_replyto')) ? $_POST['mail_replyto'] : '');
$mail_pubmail = ((x($_POST,'mail_pubmail')) ? $_POST['mail_pubmail'] : '');
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
intval(local_user())
);
if(! count($r)) {
q("INSERT INTO `mailacct` (`uid`) VALUES (%d)",
intval(local_user())
);
}
if(strlen($mail_pass)) {
$pass = '';
openssl(private_encrypt($mail_pass,$pass,$a->user['pubkey']));
q("UPDATE `mailacct` SET `pass` = '%s' WHERE `uid` = %d LIMIT 1",
dbesc(hex2bin($pass)),
intval(local_user())
);
}
$r = q("UPDATE `mailacct` SET `server` = '%s', `port` = %d, `ssltype` = '%s', `user` = '%s',
`mailbox` = 'INBOX', `reply_to` = '%s', `pubmail` = %d WHERE `uid` = %d LIMIT 1",
dbesc($mail_server),
intval($mail_port),
dbesc($mail_ssl),
dbesc($mail_user),
dbesc($mail_replyto),
intval($mail_pubmail),
intval(local_user())
);
$notify = 0;
if(x($_POST,'notify1'))
@ -249,6 +284,19 @@ function settings_content(&$a) {
if(! strlen($a->user['timezone']))
$timezone = date_default_timezone_get();
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
local_user()
);
$mail_server = ((count($r)) ? $r[0]['server'] : '');
$mail_port = ((count($r)) ? $r[0]['port'] : '');
$mail_ssl = ((count($r)) ? $r[0]['ssltype'] : '');
$mail_user = ((count($r)) ? $r[0]['user'] : '');
$mail_replyto = ((count($r)) ? $r[0]['reply_to'] : '');
$mail_pubmail = ((count($r)) ? $r[0]['pubmail'] : 0);
$pageset_tpl = load_view_file('view/pagetypes.tpl');
$pagetype = replace_macros($pageset_tpl,array(
'$normal' => (($a->user['page-flags'] == PAGE_NORMAL) ? " checked=\"checked\" " : ""),
@ -408,7 +456,23 @@ function settings_content(&$a) {
'$expire' => $expire,
'$blockw_checked' => (($blockwall) ? '' : ' checked="checked" ' ),
'$theme' => $theme_selector,
'$pagetype' => $pagetype
'$pagetype' => $pagetype,
'$lbl_imap0' => t('Email/Mailbox Setup'),
'$imap_desc' => t("If you wish to communicate with email contacts using this service \x28optional\x29, please specify how to connect to your mailbox."),
'$lbl_imap1' => t('IMAP server name:'),
'$imap_server' => $mail_server,
'$lbl_imap2' => t('IMAP port:'),
'$imap_port' => $mail_port,
'$lbl_imap3' => t("Security \x28TLS or SSL\x29:"),
'$imap_ssl' => $mail_ssl,
'$lbl_imap4' => t('Email login name:'),
'$imap_user' => $mail_user,
'$lbl_imap5' => t('Email password:'),
'$lbl_imap6' => t("Reply-to address \x28Optional\x29:"),
'$imap_replyto' => $mail_replyto,
'$lbl_imap7' => t('Send public posts to all email contacts:'),
'$pubmail_checked' => (($mail_pubmail) ? ' checked="checked" ' : ''),
));
call_hooks('settings_form',$o);

View file

@ -469,3 +469,10 @@ 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");
q("ALTER TABLE `mailacct` ADD `pubmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `reply_to` ");
q("ALTER TABLE `item` ADD `pubmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `private` ");
}

View file

@ -164,7 +164,35 @@ $profile_in_net_dir
<input type="submit" name="submit" class="settings-submit" value="$submit" />
</div>
<h3 class="settings-imap">$lbl_imap0</h3>
<p>
$imap_desc
</p>
<label for="imap-server" id="settings-label-imap1">$lbl_imap1</label>
<input type="text" id="imap-server" name="mail_server" value="$imap_server" />
<div id="imap-server-end"></div>
<label for="imap-port" id="settings-label-imap2">$lbl_imap2</label>
<input type="text" id="imap-port" name="mail_port" value="$imap_port" />
<div id="imap-port-end"></div>
<label for="imap-ssl" id="settings-label-imap3">$lbl_imap3</label>
<input type="text" id="imap-ssl" name="mail_ssl" value="$imap_ssl" />
<div id="imap-ssl-end"></div>
<label for="imap-user" id="settings-label-imap4">$lbl_imap4</label>
<input type="text" id="imap-user" name="mail_user" value="$imap_user" />
<div id="imap-user-end"></div>
<label for="imap-pass" id="settings-label-imap5">$lbl_imap5</label>
<input type="password" id="imap-pass" name="mail_pass" value="" />
<div id="imap-pass-end"></div>
<label for="imap-replyto" id="settings-label-imap6">$lbl_imap6</label>
<input type="text" id="imap-replyto" name="mail_replyto" value="$imap_replyto" />
<div id="imap-replyto-end"></div>
<label for="imap-pubmail" id="settings-label-imap7">$lbl_imap7</label>
<input type="checkbox" name="mail_pubmail" id="imap-pubmail" $pubmail_checked value="1" />
<div id="imap-pubmail-end"></div>
<div class="settings-submit-wrapper" >
<input type="submit" name="submit" class="settings-submit" value="$submit" />
</div>
<h3 class="settings-heading">$lbl_advn</h3>

View file

@ -402,7 +402,14 @@ input#dfrn-url {
#notify2-end,
#notify3-end,
#notify4-end,
#notify5-end {
#notify5-end,
#imap-server-end,
#imap-port-end,
#imap-ssl-end,
#imap-user-end,
#imap-pass-end,
#imap-replyto-end,
#imap-pubmail-end {
margin-bottom: 5px;
clear: both;
}
@ -423,7 +430,14 @@ input#dfrn-url {
#settings-label-notify2,
#settings-label-notify3,
#settings-label-notify4,
#settings-label-notify5 {
#settings-label-notify5,
#settings-label-imap1,
#settings-label-imap2,
#settings-label-imap3,
#settings-label-imap4,
#settings-label-imap5,
#settings-label-imap6,
#settings-label-imap7 {
float: left;
width: 200px;
}
@ -443,7 +457,14 @@ input#dfrn-url {
#notify2,
#notify3,
#notify4,
#notify5 {
#notify5,
#imap-server,
#imap-port,
#imap-ssl,
#imap-user,
#imap-pass,
#imap-replyto,
#imap-pubmail {
float: left;
margin-bottom: 20px;
}

View file

@ -529,7 +529,14 @@ input#dfrn-url {
#notify2-end,
#notify3-end,
#notify4-end,
#notify5-end {
#notify5-end,
#imap-server-end,
#imap-port-end,
#imap-ssl-end,
#imap-user-end,
#imap-pass-end,
#imap-replyto-end,
#imap-pubmail-end {
margin-bottom: 5px;
clear: both;
}
@ -550,7 +557,14 @@ input#dfrn-url {
#settings-label-notify2,
#settings-label-notify3,
#settings-label-notify4,
#settings-label-notify5 {
#settings-label-notify5,
#settings-label-imap1,
#settings-label-imap2,
#settings-label-imap3,
#settings-label-imap4,
#settings-label-imap5,
#settings-label-imap6,
#settings-label-imap7 {
float: left;
width: 200px;
}
@ -570,7 +584,14 @@ input#dfrn-url {
#notify2,
#notify3,
#notify4,
#notify5 {
#notify5,
#imap-server,
#imap-port,
#imap-ssl,
#imap-user,
#imap-pass,
#imap-replyto,
#imap-pubmail {
float: left;
margin-bottom: 20px;
}