diff options
author | Alvaro Herrera | 2010-01-09 03:55:06 +0000 |
---|---|---|
committer | Alvaro Herrera | 2010-01-09 03:55:06 +0000 |
commit | 9cf7d420bf830b91bcba95e3d4a0e5a6c1b917ec (patch) | |
tree | 72ba16b1a6e95a2ef347135e9ccae21d7b837d5b | |
parent | 712b634b38f4e8399170e9799e224b3c93169d29 (diff) |
Avoid assuming that it's possible to have unbounded numbers of entries in a
directory.
git-svn-id: file:///Users/dpage/pgweb/svn-repo/trunk@2616 8f5c7a92-453e-0410-a47f-ad33c8a6b003
-rwxr-xr-x | archives/bin/splitmbox | 14 | ||||
-rw-r--r-- | archives/html/msgtxt.php | 18 |
2 files changed, 27 insertions, 5 deletions
diff --git a/archives/bin/splitmbox b/archives/bin/splitmbox index ee289461..06d476a9 100755 --- a/archives/bin/splitmbox +++ b/archives/bin/splitmbox @@ -7,8 +7,10 @@ # # $Id$ +. $HOME/etc/archives.conf + mbox=$1 -destdir=/home/archives/messages +destdir=$SPLITMBOX_DEST export destdir # *() and other patterns need this set @@ -42,17 +44,21 @@ for message in $tempdir/msg.*; do messageid=${messageid##*([< ])} messageid=${messageid%%>} messageid=${messageid//\//_} - # fetch the part after the first @ (inclusive) + # fetch the part after the first @ (inclusive), and split in two levels of + # dirs of two chars. So for @gmail.com we get gm/ai/@gmail.com dir=${messageid##*([^@])} + dir=${dir:1:2}/${dir:3:2}/$dir # escape [, ? and * from it (these are special chars for bash ${} expansion) diresc=${dir/[/\\[} diresc=${diresc/\*/\\*} diresc=${diresc/\?/\\?} - # and fetch the part before the @ (i.e. strip $dir) + # and fetch the part before the @ (i.e. strip $dir), and split in two levels + # of dirs of two chars file=${messageid%%$diresc} + dir=$dir/${file:0:2}/${file:2:2} # create the directory if needed if [ ! -d "$destdir/$dir" ]; then - mkdir -v "$destdir/$dir" || echo "failed to create $destdir/$dir" + mkdir -p "$destdir/$dir" || echo "failed to create $destdir/$dir" fi # and link the message into place if [ ! -f "$destdir/$dir/$file" ]; then diff --git a/archives/html/msgtxt.php b/archives/html/msgtxt.php index ee8b02ee..86f7a9d3 100644 --- a/archives/html/msgtxt.php +++ b/archives/html/msgtxt.php @@ -7,7 +7,23 @@ $parts = split("@", $id, 2); header("Content-type: text/plain"); -$filename= "/home/archives/messages/@" . $parts[1] . "/" . $parts[0]; +$dir = substr($parts[1], 0, 2) . + "/" . + substr($parts[1], 2, 2) . + "/@" . + $parts[1] . + "/" . + substr($parts[0], 0, 2) . + "/" . + substr($parts[0], 2, 2); + + +$filename= $_SERVER['DOCUMENT_ROOT'] . "/../messages/" . $dir . "/" . $id; +if (!file_exists($filename)) { + print "No message with Message-Id " . $_GET["id"] ." found\n"; + exit; +} + $file = fopen($filename, "r"); if (!$file) { print "not found\n"; |