Exemple #1
0
function xchan_mail_query(&$item)
{
    $arr = array();
    $chans = null;
    if ($item) {
        if ($item['from_xchan'] && !in_array($item['from_xchan'], $arr)) {
            $arr[] = "'" . dbesc($item['from_xchan']) . "'";
        }
        if ($item['to_xchan'] && !in_array($item['to_xchan'], $arr)) {
            $arr[] = "'" . dbesc($item['to_xchan']) . "'";
        }
    }
    if (count($arr)) {
        $chans = q("select xchan.*,hubloc.* from xchan left join hubloc on hubloc_hash = xchan_hash\n\t\t\twhere xchan_hash in (" . implode(',', $arr) . ") and hubloc_primary = 1");
    }
    if ($chans) {
        $item['from'] = find_xchan_in_array($item['from_xchan'], $chans);
        $item['to'] = find_xchan_in_array($item['to_xchan'], $chans);
    }
}
Exemple #2
0
function private_messages_fetch_conversation($channel_id, $messageitem_id, $updateseen = false)
{
    // find the parent_mid of the message being requested
    $r = q("SELECT parent_mid from mail WHERE channel_id = %d and id = %d limit 1", intval($channel_id), intval($messageitem_id));
    if (!$r) {
        return array();
    }
    $messages = q("select * from mail where parent_mid = '%s' and channel_id = %d order by created asc", dbesc($r[0]['parent_mid']), intval($channel_id));
    if (!$messages) {
        return array();
    }
    $chans = array();
    foreach ($messages as $rr) {
        $s = "'" . dbesc(trim($rr['from_xchan'])) . "'";
        if (!in_array($s, $chans)) {
            $chans[] = $s;
        }
        $s = "'" . dbesc(trim($rr['to_xchan'])) . "'";
        if (!in_array($s, $chans)) {
            $chans[] = $s;
        }
    }
    $c = q("select * from xchan where xchan_hash in (" . implode(',', $chans) . ")");
    foreach ($messages as $k => $message) {
        $messages[$k]['from'] = find_xchan_in_array($message['from_xchan'], $c);
        $messages[$k]['to'] = find_xchan_in_array($message['to_xchan'], $c);
        if (intval($messages[$k]['mail_obscured'])) {
            if ($messages[$k]['title']) {
                $messages[$k]['title'] = base64url_decode(str_rot47($messages[$k]['title']));
            }
            if ($messages[$k]['body']) {
                $messages[$k]['body'] = base64url_decode(str_rot47($messages[$k]['body']));
            }
        }
    }
    if ($updateseen) {
        $r = q("UPDATE `mail` SET mail_seen = 1 where mail_seen = 0 and parent_mid = '%s' AND channel_id = %d", dbesc($r[0]['parent_mid']), intval($channel_id));
    }
    return $messages;
}
Exemple #3
0
function private_messages_fetch_conversation($channel_id, $messageitem_id, $updateseen = false)
{
    // find the parent_mid of the message being requested
    $r = q("SELECT parent_mid from mail WHERE channel_id = %d and id = %d limit 1", intval($channel_id), intval($messageitem_id));
    if (!$r) {
        return array();
    }
    $messages = q("select * from mail where parent_mid = '%s' and channel_id = %d order by created asc", dbesc($r[0]['parent_mid']), intval($channel_id));
    if (!$messages) {
        return array();
    }
    $chans = array();
    foreach ($messages as $rr) {
        $s = "'" . dbesc(trim($rr['from_xchan'])) . "'";
        if (!in_array($s, $chans)) {
            $chans[] = $s;
        }
        $s = "'" . dbesc(trim($rr['to_xchan'])) . "'";
        if (!in_array($s, $chans)) {
            $chans[] = $s;
        }
    }
    $c = q("select * from xchan where xchan_hash in (" . implode(',', $chans) . ")");
    foreach ($messages as $k => $message) {
        $messages[$k]['from'] = find_xchan_in_array($message['from_xchan'], $c);
        $messages[$k]['to'] = find_xchan_in_array($message['to_xchan'], $c);
        if ($messages[$k]['mail_flags'] & MAIL_OBSCURED) {
            $key = get_config('system', 'prvkey');
            if ($messages[$k]['title']) {
                $messages[$k]['title'] = crypto_unencapsulate(json_decode_plus($messages[$k]['title']), $key);
            }
            if ($messages[$k]['body']) {
                $messages[$k]['body'] = crypto_unencapsulate(json_decode_plus($messages[$k]['body']), $key);
            }
        }
    }
    if ($updateseen) {
        $r = q("UPDATE `mail` SET mail_flags = (mail_flags ^ %d) where not (mail_flags & %d) and parent_mid = '%s' AND channel_id = %d", intval(MAIL_SEEN), intval(MAIL_SEEN), dbesc($r[0]['parent_mid']), intval($channel_id));
    }
    return $messages;
}