Example #1
1
function email_get_msg($mbox, $uid, $reply)
{
    $ret = array();
    $struc = $mbox && $uid ? @imap_fetchstructure($mbox, $uid, FT_UID) : null;
    if (!$struc) {
        return $ret;
    }
    // for testing purposes: Collect imported mails
    // $file = tempnam("/tmp/friendica2/", "mail-in-");
    // file_put_contents($file, json_encode($struc));
    if (!$struc->parts) {
        $ret['body'] = email_get_part($mbox, $uid, $struc, 0, 'html');
        $html = $ret['body'];
        if (trim($ret['body']) == '') {
            $ret['body'] = email_get_part($mbox, $uid, $struc, 0, 'plain');
        } else {
            $ret['body'] = html2bbcode($ret['body']);
        }
    } else {
        $text = '';
        $html = '';
        foreach ($struc->parts as $ptop => $p) {
            $x = email_get_part($mbox, $uid, $p, $ptop + 1, 'plain');
            if ($x) {
                $text .= $x;
            }
            $x = email_get_part($mbox, $uid, $p, $ptop + 1, 'html');
            if ($x) {
                $html .= $x;
            }
        }
        if (trim($html) != '') {
            $ret['body'] = html2bbcode($html);
        } else {
            $ret['body'] = $text;
        }
    }
    $ret['body'] = removegpg($ret['body']);
    $msg = removesig($ret['body']);
    $ret['body'] = $msg['body'];
    $ret['body'] = convertquote($ret['body'], $reply);
    if (trim($html) != '') {
        $ret['body'] = removelinebreak($ret['body']);
    }
    $ret['body'] = unifyattributionline($ret['body']);
    return $ret;
}
Example #2
0
function email_get_msg($mbox, $uid, $reply)
{
    $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, 'html');
        $html = $ret['body'];
        if (trim($ret['body']) == '') {
            $ret['body'] = email_get_part($mbox, $uid, $struc, 0, 'plain');
        } else {
            $ret['body'] = html2bbcode($ret['body']);
        }
    } else {
        $text = '';
        $html = '';
        foreach ($struc->parts as $ptop => $p) {
            $x = email_get_part($mbox, $uid, $p, $ptop + 1, 'plain');
            if ($x) {
                $text .= $x;
            }
            $x = email_get_part($mbox, $uid, $p, $ptop + 1, 'html');
            if ($x) {
                $html .= $x;
            }
        }
        if (trim($html) != '') {
            $ret['body'] = html2bbcode($html);
        } else {
            $ret['body'] = $text;
        }
    }
    $ret['body'] = removegpg($ret['body']);
    $msg = removesig($ret['body']);
    $ret['body'] = $msg['body'];
    $ret['body'] = convertquote($ret['body'], $reply);
    if (trim($html) != '') {
        $ret['body'] = removelinebreak($ret['body']);
    }
    $ret['body'] = unifyattributionline($ret['body']);
    return $ret;
}