Theiling Online    Sitemap    Conlang Mailing List HQ   

Maybe another helpful script

From:Carsten Becker <naranoieati@...>
Date:Friday, August 20, 2004, 10:17

First some advertising and information about my
'product' ...

Now that I got it working, I want to share a little PHP
script that might be helpful for you (if you receive MIME
Digests from here and your mail program cannot import them

Because I have no internet on my own computer, I have to use
either my mother's or my father's computer. My dad doesn't
like it when I use his computer, so I use my mother's one
for internet and email business. I keep the archive of the
list on *my* computer, so I must transfer the MIME digests
with a floppy disc once per day. And this is where the
trouble begins: Under Windows, it was no problem to
open .eml files with Outlook Express, but now that I'm
often use Linux and have my offline mail archive there,
too, I use KMail for organizing my emails. KMail has the
nice feature that it can import emails from plain files
which Evolution is not able to do AFAIK. I don't know what
Mutt or even Emacs can do here because I've never used them
up to now. KMail, or more correctly the KMailCVT addon, is
unfortunately only able to import plain text and no MIME
Digests or other mails with attachments.
However, I discovered that all digests I get from the list
contain a line '--[30-positions-long-alphanummeric-code]'
which tells the mail program where to split the mails.
Because as I said, KMailCVT is not able to do this job as
it seems, I wrote a PHP script that gets a digest file,
finds out the boundary code and saves the splitted parts as
single text files which I can import into KMail afterwards.

Here's the code finally:


    $file   =   $_GET["file"];
    $mail   =   file_get_contents($file);

    list($pre,$split)    =    explode('boundary="',$mail);
    list($split,$after)  =    explode('"',$split);

    echo "--".$split."<br><br><br>";

    $mails  =   split("--".$split,$mail);
    $date   =   date("Ymd",filemtime($file));
    $folder =   "/var/www/html/mails";

    $a      =   count($mails)-2;

    for($i = 1; $i <= $a; $i++) {
        $z = $i-1;
        $saveas = fopen("$folder/[$date]$z.eml","a+b");

echo substr($mails[$i],0,500)." ...<hr>";

    echo ("The file $file was split into $a single messages
which were saved to $folder.");


The only problem is that the form I made for giving the
filename (not included here) somehow does not work
correctly: E.g. the filename is "/mnt/floppy/CONLANG Digest
- 17 Aug 2004 to 18 Aug 2004 (#2004-230).eml", only the
last part is submitted (line #3 changed to $_POST["file"]
of course). Even when renaming the file to "2004-230.eml",
instead of "/mnt/floppy/2004-230.eml" only "2004-230.eml"
is submitted, which of course the script cannot find. Why
not? I use "<input type="file" enctype="text/plain"
name="file" size="30">" in a normal HTML file here. <form>
is set to 'method="post"', too. So actually, there
shouldn't be any difficulties. I'm using PHP 4.3.4 (CGI) on
an Apache 2.0.49, both was auto-installed when I installed


Eri silveváng aibannama padangin.
Nivaie evaenain eri ming silvoieváng caparei.
- Antoine de Saint-Exupéry, Le Petit Prince