Example #1
0
/**
 * For reference see:
 * http://www.nacs.uci.edu/indiv/ehood/MIME/2045/rfc2045.html
 * http://www.faqs.org/rfcs/rfc2045.html
 * (RFC 1521 has been superceeded by RFC 2045 & others).
 *
 * Also see http://www.faqs.org/rfcs/rfc2822.html
 *
 *
 * Notes on content-transfer-encoding.
 *
 * "7bit" means short lines of US-ASCII.
 * "8bit" means short lines of octets with (possibly) the high-order bit set.
 * "binary" means lines are not necessarily short enough for SMTP
 * transport, and non-ASCII characters may be present.
 *
 * Only "7bit", "quoted-printable", and "base64" are universally safe
 * for transport via e-mail.  (Though many MTAs can/will be configured to
 * automatically convert encodings to a safe type if they receive
 * mail encoded in '8bit' and/or 'binary' encodings.
 */
function MimeifyPageRevision(&$page, &$revision)
{
    // $wikidb =& $revision->_wikidb;
    // $page = $wikidb->getPage($revision->getName());
    // FIXME: add 'hits' to $params
    $params = array('pagename' => $page->getName(), 'flags' => "", 'author' => $revision->get('author'), 'version' => $revision->getVersion(), 'lastmodified' => $revision->get('mtime'));
    if ($page->get('mtime')) {
        $params['created'] = $page->get('mtime');
    }
    if ($page->get('locked')) {
        $params['flags'] = 'PAGE_LOCKED';
    }
    if ($revision->get('author_id')) {
        $params['author_id'] = $revision->get('author_id');
    }
    if ($revision->get('markup')) {
        // what is the default? we must use 1
        $params['markup'] = $revision->get('markup');
    }
    if ($revision->get('summary')) {
        $params['summary'] = $revision->get('summary');
    }
    if ($page->get('hits')) {
        $params['hits'] = $page->get('hits');
    }
    if ($page->get('owner')) {
        $params['owner'] = $page->get('owner');
    }
    if ($page->get('perm') and class_exists('PagePermission')) {
        $acl = getPagePermissions($page);
        $params['acl'] = $acl->asAclLines();
        //TODO: convert to multiple lines? acl-view => groups,...; acl-edit => groups,...
    }
    $params['charset'] = $GLOBALS['charset'];
    // Non-US-ASCII is not allowed in Mime headers (at least not without
    // special handling) --- so we urlencode all parameter values.
    foreach ($params as $key => $val) {
        $params[$key] = rawurlencode($val);
    }
    if (isset($params['acl'])) {
        // default: "view:_EVERY; edit:_AUTHENTICATED; create:_AUTHENTICATED,_BOGOUSER; ".
        //          "list:_EVERY; remove:_ADMIN,_OWNER; change:_ADMIN,_OWNER; dump:_EVERY; "
        $params['acl'] = str_replace(array("%3A", "%3B%20", "%2C"), array(":", "; ", ","), $params['acl']);
    }
    $out = MimeContentTypeHeader('application', 'x-phpwiki', $params);
    $out .= sprintf("Content-Transfer-Encoding: %s\r\n", STRICT_MAILABLE_PAGEDUMPS ? 'quoted-printable' : 'binary');
    $out .= "\r\n";
    foreach ($revision->getContent() as $line) {
        // This is a dirty hack to allow saving binary text files. See above.
        $line = rtrim($line);
        if (STRICT_MAILABLE_PAGEDUMPS) {
            $line = QuotedPrintableEncode(rtrim($line));
        }
        $out .= "{$line}\r\n";
    }
    return $out;
}
Example #2
0
function MimeifyPage($pagehash)
{
    extract($pagehash);
    // FIXME: add 'hits' to $params
    $params = array('pagename' => rawurlencode($pagename), 'author' => rawurlencode($author), 'version' => $version, 'flags' => "", 'lastmodified' => $lastmodified, 'created' => $created);
    if (($flags & FLAG_PAGE_LOCKED) != 0) {
        $params['flags'] = 'PAGE_LOCKED';
    }
    for ($i = 1; $i <= NUM_LINKS; $i++) {
        if ($ref = $refs[$i]) {
            $params["ref{$i}"] = rawurlencode($ref);
        }
    }
    $out = MimeContentTypeHeader('application', 'x-phpwiki', $params);
    $out .= "Content-Transfer-Encoding: quoted-printable\r\n";
    $out .= "\r\n";
    reset($content);
    while (list($junk, $line) = each($content)) {
        $out .= QuotedPrintableEncode(chop($line)) . "\r\n";
    }
    return $out;
}