From 39253e0dddd82d0bf7c1a5ff126e41ed3d9573d5 Mon Sep 17 00:00:00 2001 From: dairiki Date: Fri, 25 Jan 2002 16:46:02 +0000 Subject: [PATCH] Moved Content-Transfer-Encoding generation back into MimeifyPageRevision(). (Note that moving it to MailifyPage() broke the zip-dumps. (In multipart MIME message, each part needs to specify its transfer-encoding --- furthermore the top (multipart) part must not be encoded. Urlencode all mime-type parameters (since only US-ASCII is allowed in the mail headers.) Eleminated the global $pagedump_format in favor of new define STRICT_MAILABLE_PAGEDUMPS. Cleaned up the generated mail headers a bit. Don't include From: unless STRICT_MAILABLE_PAGEDUMPS is set. Don't put RCS id tags in headers. There should only be RCS tags in files which actually come from RCS(/CVS). For now, I think we should manually insert headers like: X-Rcs-Id: $Id$ in the pgsrc files. Note that this is legal. 'Unstructured' header values can contain any US-ASCII characters other than carriage-return and new-line. (see RFC 2822.) (Also note that Content-Id:'s must be valid 'msg-id's (see RFC 2822) --- they look roughly like bracketed e-mail addresses: "<.*@.*>".) Are MTA's really allowed to strip X-* headers? (It's not an issue, in any case, since, as noted above, only the files which are in CVS should have X-Rcs-Id anyhow.) git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@1569 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- index.php | 18 +++++++++++---- lib/loadsave.php | 57 ++++++++++++++++++++---------------------------- lib/ziplib.php | 57 ++++++++++++++++++++++++++++++++---------------- 3 files changed, 76 insertions(+), 56 deletions(-) diff --git a/index.php b/index.php index d8c7ce75c..f31e9793e 100644 --- a/index.php +++ b/index.php @@ -80,7 +80,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA define ('PHPWIKI_VERSION', '1.3.2-jeffs-hacks'); require "lib/prepend.php"; -rcs_id('$Id: index.php,v 1.73 2002-01-25 06:03:52 carstenklapp Exp $'); +rcs_id('$Id: index.php,v 1.74 2002-01-25 16:46:02 dairiki Exp $'); ///////////////////////////////////////////////////////////////////// // @@ -111,9 +111,19 @@ define('ADMIN_PASSWD', ""); define('ZIPDUMP_AUTH', false); -// This setting determines the type of page dumps. Must be one of -// "quoted-printable" or "binary". -$pagedump_format = "quoted-printable"; +// If you define this to true, (MIME-type) page-dumps (either zip dumps, +// or "dumps to directory" will be encoded using the quoted-printable +// encoding. If you're actually thinking of mailing the raw page dumps, +// then this might be useful, since (among other things,) it ensures +// that all lines in the message body are under 80 characters in length. +// +// Also, setting this will cause a few additional mail headers +// to be generated, so that the resulting dumps are valid +// RFC 2822 e-mail messages. +// +// Probably, you can just leave this set to false, in which case you get +// raw ('binary' content-encoding) page dumps. +define('STRICT_MAILABLE_PAGEDUMPS', false); // The maximum file upload size. define('MAX_UPLOAD_SIZE', 16 * 1024 * 1024); diff --git a/lib/loadsave.php b/lib/loadsave.php index 107fcfb4f..7e0b60fff 100644 --- a/lib/loadsave.php +++ b/lib/loadsave.php @@ -1,4 +1,4 @@ -getCurrentRevision(); - $from = isset($SERVER_ADMIN) ? $SERVER_ADMIN : 'foo@bar'; - $head = ""; - /** - * "7bit" means short lines of US-ASCII. - * "8bit" means short lines of octets with the high-order bit set. - * "binary" means lines are not necessarily short enough for SMTP - * transport, and non-ASCII characters may be present. - */ - if ($pagedump_format == 'quoted-printable') { - $head = "From $from " . CTime(time()) . "\r\n"; + $head = ''; + + if (STRICT_MAILABLE_PAGEDUMPS) { + $from = defined('SERVER_ADMIN') ? SERVER_ADMIN : 'foo@bar'; + //This is for unix mailbox format: (not RFC (2)822) + // $head .= "From $from " . CTime(time()) . "\r\n"; $head .= "Subject: " . rawurlencode($page->getName()) . "\r\n"; $head .= "From: $from (PhpWiki)\r\n"; - $head .= "Date: " . Rfc2822DateTime($current->get('mtime')) . "\r\n"; - $head .= sprintf("Mime-Version: 1.0 (Produced by PhpWiki %s)\r\n", - PHPWIKI_VERSION); - $head .= "Content-Transfer-Encoding: quoted-printable\r\n"; - } else if ($pagedump_format == 'binary') { - $head .= sprintf("Mime-Version: 1.0 (Produced by PhpWiki %s)\r\n", - PHPWIKI_VERSION."+carsten's-binary-hack"); - $head .= "Content-Transfer-Encoding: binary\r\n"; - } else { - $out .= "Content-Transfer-Encoding: " . $pagedump_format ."\r\n"; + // RFC 2822 requires only a Date: and originator (From:) + // field, however the obsolete standard RFC 822 also + // requires a destination field. + $head .= "To: $from (PhpWiki)\r\n"; } + $head .= "Date: " . Rfc2822DateTime($current->get('mtime')) . "\r\n"; + $head .= sprintf("Mime-Version: 1.0 (Produced by PhpWiki %s)\r\n", + PHPWIKI_VERSION); - // This might be better for actually emailing wiki pages--gateways - // are allowed to arbitrarily discard any X-* headers. - // The $Id\$ also contains : so the line must be quoted. - $head .= "Content-ID: \"rcs_id('$" ."Id" ."$" ."')\"\r\n"; - + // This should just be entered by hand (or by script?) + // in the actual pgsrc files, since only they should have + // RCS ids. + //$head .= "X-Rcs-Id: \$Id\$\r\n"; + $iter = $page->getAllRevisions(); $parts = array(); while ($revision = $iter->next()) { @@ -150,7 +143,6 @@ function MakeWikiZip (&$request) function DumpToDir (&$request) { - global $pagedump_format; $directory = $request->getArg('directory'); if (empty($directory)) $request->finish(_("You must specify a directory to dump to")); @@ -160,13 +152,12 @@ function DumpToDir (&$request) if (! mkdir($directory, 0755)) $request->finish(fmt("Cannot create directory '%s'", $directory)); else - $html = sprintf(_("Created directory '%s' for the page dump..."), - $directory) . "
\n"; + $html = HTML::p(fmt("Created directory '%s' for the page dump...", + $directory)); } else { - $html = sprintf(_("Using directory '%s'"),$directory) . "
\n"; + $html = HTML::p(fmt("Using directory '%s'", $directory)); } - $html .= "MIME " . $pagedump_format . "
\n"; StartLoadDump($request, _("Dumping Pages"), $html); $dbi = $request->getDbh(); diff --git a/lib/ziplib.php b/lib/ziplib.php index 74ac73f2d..d8a421e74 100644 --- a/lib/ziplib.php +++ b/lib/ziplib.php @@ -1,4 +1,4 @@ -getPage(); // FIXME: add 'hits' to $params - $params = array('pagename' => rawurlencode($page->getName()), - 'author' => rawurlencode($revision->get('author')), + $params = array('pagename' => $page->getName(), + 'author' => $revision->get('author'), 'version' => $revision->getVersion(), 'flags' => "", - 'lastmodified' => $revision->get('mtime')); - - if ($pagedump_format == 'quoted-printable') { - $params = array_merge(array('charset' => 'US-ASCII', - 'format' => 'flowed'), $params); - } else if ($pagedump_format == 'binary') { - $params = array_merge(array('charset' => 'ISO-8859-1'), $params); - } else { // This is a little risky - $params = array_merge(array('charset' => CHARSET), $params); - } + 'lastmodified' => $revision->get('mtime'), + 'charset' => CHARSET); + 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'); - + + // 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); $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. - $out .= ($pagedump_format == "quoted-printable") ? - QuotedPrintableEncode(chop($line)) : chop($line); - $out .= "\r\n"; + $line = rtrim($line); + if (STRICT_MAILABLE_PAGEDUMPS) + $line = QuotedPrintableEncode(rtrim($line)); + $out .= "$line\r\n"; } return $out; } -- 2.45.0