Esempio n. 1
0
File: zot.php Progetto: 23n/hubzilla
function process_mail_delivery($sender, $arr, $deliveries)
{
    $result = array();
    if ($sender['hash'] != $arr['from_xchan']) {
        logger('process_mail_delivery: sender is not mail author');
        return;
    }
    foreach ($deliveries as $d) {
        $DR = new DReport(z_root(), $sender['hash'], $d['hash'], $arr['mid']);
        $r = q("select * from channel where channel_hash = '%s' limit 1", dbesc($d['hash']));
        if (!$r) {
            $DR->update('recipient not found');
            $result[] = $DR->get();
            continue;
        }
        $channel = $r[0];
        $DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>');
        if (!perm_is_allowed($channel['channel_id'], $sender['hash'], 'post_mail')) {
            logger("permission denied for mail delivery {$channel['channel_id']}");
            $DR->update('permission denied');
            $result[] = $DR->get();
            continue;
        }
        $r = q("select id from mail where mid = '%s' and channel_id = %d limit 1", dbesc($arr['mid']), intval($channel['channel_id']));
        if ($r) {
            if (intval($arr['mail_recalled'])) {
                $x = q("delete from mail where id = %d and channel_id = %d", intval($r[0]['id']), intval($channel['channel_id']));
                $DR->update('mail recalled');
                $result[] = $DR->get();
                logger('mail_recalled');
            } else {
                $DR->update('duplicate mail received');
                $result[] = $DR->get();
                logger('duplicate mail received');
            }
            continue;
        } else {
            $arr['account_id'] = $channel['channel_account_id'];
            $arr['channel_id'] = $channel['channel_id'];
            $item_id = mail_store($arr);
            $DR->update('mail delivered');
            $result[] = $DR->get();
        }
    }
    return $result;
}
Esempio n. 2
0
function import_mail($channel, $mails, $sync = false)
{
    if ($channel && $mails) {
        foreach ($mails as $mail) {
            if (array_key_exists('flags', $mail) && in_array('deleted', $mail['flags'])) {
                q("delete from mail where mid = '%s' and uid = %d limit 1", dbesc($mail['message_id']), intval($channel['channel_id']));
                continue;
            }
            if (array_key_exists('flags', $mail) && in_array('recalled', $mail['flags'])) {
                q("update mail set mail_recalled = 1 where mid = '%s' and uid = %d limit 1", dbesc($mail['message_id']), intval($channel['channel_id']));
                continue;
            }
            $m = get_mail_elements($mail);
            if (!$m) {
                continue;
            }
            $m['aid'] = $channel['channel_account_id'];
            $m['uid'] = $channel['channel_id'];
            $mail_id = mail_store($m);
            if ($sync && $mail_id) {
                Zotlabs\Daemon\Master::Summon(array('Notifier', 'single_mail', $mail_id));
            }
        }
    }
}
Esempio n. 3
0
function process_mail_delivery($sender, $arr, $deliveries)
{
    $result = array();
    if ($sender['hash'] != $arr['from_xchan']) {
        logger('process_mail_delivery: sender is not mail author');
        return;
    }
    foreach ($deliveries as $d) {
        $r = q("select * from channel where channel_hash = '%s' limit 1", dbesc($d['hash']));
        if (!$r) {
            $result[] = array($d['hash'], 'not found');
            continue;
        }
        $channel = $r[0];
        if (!perm_is_allowed($channel['channel_id'], $sender['hash'], 'post_mail')) {
            logger("permission denied for mail delivery {$channel['channel_id']}");
            $result[] = array($d['hash'], 'permission denied', $channel['channel_name'], $arr['mid']);
            continue;
        }
        $r = q("select id from mail where mid = '%s' and channel_id = %d limit 1", dbesc($arr['mid']), intval($channel['channel_id']));
        if ($r) {
            if ($arr['mail_flags'] & MAIL_RECALLED) {
                $x = q("delete from mail where id = %d and channel_id = %d", intval($r[0]['id']), intval($channel['channel_id']));
                $result[] = array($d['hash'], 'mail recalled', $channel['channel_name'], $arr['mid']);
                logger('mail_recalled');
            } else {
                $result[] = array($d['hash'], 'duplicate mail received', $channel['channel_name'], $arr['mid']);
                logger('duplicate mail received');
            }
            continue;
        } else {
            $arr['account_id'] = $channel['channel_account_id'];
            $arr['channel_id'] = $channel['channel_id'];
            $item_id = mail_store($arr);
            $result[] = array($d['hash'], 'mail delivered', $channel['channel_name'], $arr['mid']);
        }
    }
    return $result;
}
Esempio n. 4
0
function import_mail($channel, $mails)
{
    if ($channel && $mails) {
        foreach ($mails as $mail) {
            if (array_key_exists('flags', $mail) && in_array('deleted', $mail['flags'])) {
                q("delete from mail where mid = '%s' and uid = %d limit 1", dbesc($mail['message_id']), intval($channel['channel_id']));
                continue;
            }
            if (array_key_exists('flags', $mail) && in_array('recalled', $mail['flags'])) {
                q("update mail set mail_recalled = 1 where mid = '%s' and uid = %d limit 1", dbesc($mail['message_id']), intval($channel['channel_id']));
                continue;
            }
            $m = get_mail_elements($mail);
            if (!$m) {
                continue;
            }
            $m['aid'] = $channel['channel_account_id'];
            $m['uid'] = $channel['channel_id'];
            mail_store($m);
        }
    }
}