3 Sends out a backup MIME/multipart archive containing only the latest
4 versions of all text pages. This cannot be easily deciphered by an
5 ordinary mail reader, and there is yet no commandline utility for
6 this kind of mime archives; but it is anyhow a good format for backup
7 purposes (because an import tool is quickly made).
8 Please see also "S92binbackup" which sends backups already useful with
9 the t_transfer utility.
12 // define("MIMEBACKUP_TO", "you@example.com"); // who gets the backup
16 if (defined("MIMEBACKUP_TO")) {
20 echo "[$cron]: Searching _TEXT pages to generate MIME/multipart backup mail...\n";
22 #-- search for _TEXT pages
23 $result = ewiki_db::GETALL(array("id", "version", "flags"));
24 while ($row = $result->get(0, 0x1037)) {
26 $row = ewiki_db::GET($row["id"]);
27 if (!$row || !$row["id"] || !$row["content"]) {
31 #-- add (we could run out of memory with this!)
34 echo "[$cron]: Found " . count($parts) . " pages\n";
37 $BND = "cut-here-".md5(time())."-cut-here";
39 ."Content-Type: text/plain\n"
41 ."This is a backup of " . EWIKI_NAME . ". All text pages are contained\n"
42 ."in this mail as MIME/multipart embedded files; use a better mail reader\n"
43 ."if you cannot decompose it easily.\n"
45 . multipart_parallel($parts, $boundary, $inj_header)
48 echo "[$cron]: Sending backup data to " . MIMEBACKUP_TO . "\n";
51 "[backup] " . EWIKI_NAME . ":",
53 "Content-Type: multipart/mixed; boundary=$BND\n"
54 ."X-Mailer: $ewiki_config[ua] run-parts/$cron\n"
55 ."From: ewiki@$_SERVER[SERVER_NAME]\n"
56 ."Reply-To: trashbin@example.com\n"
64 #-- produces a (probably invalid) multipart stream
65 function multipart_parallel(&$parts) {
67 $boundary = preg_replace("/(........)/", '$1-', md5(serialize($parts)))
68 . "ewiki-mimebackup"; //@FIXME: must be checked for being unique
70 foreach ($parts as $i=>$row) {
71 $fn = urlencode($row["id"]);
72 $created = gmstrftime($ewiki_t["C"]["DATE"], $row["created"]);
73 $lm = gmstrftime($ewiki_t["C"]["DATE"], $row["lastmodified"]);
74 $text .= "--$boundary\n"
75 . "Content-Type: text/x-wiki; variant=ewiki; charset=iso-8859-1\n"
76 . "Content-Disposition: inline; filename=\"$fn\"\n"
77 . "X-Flags: $row[flags]\n"
78 . "Content-Version: $row[version]\n" // HTTP header, but hey!
79 . "X-Created: $created\n"
80 . "Last-Modified: $lm\n" // also only allowed in HTTP exactly
86 $text .= "--$boundary--\n";
89 $text = wordwrap(base64_encode(gzencode($text)), 78, "\n", 1);
93 = "Content-Type: x-multipart/parallel; boundary=$boundary\n"
94 . "Content-Disposition: attachment; filename=".EWIKI_NAME.".mar.gz\n"
95 . "Content-Encoding: gzip\n"
96 . "Content-Transfer-Encoding: base64\n"