khippy has asked for the wisdom of the Perl Monks concerning the following question:

Hi knowledgers,
Imagine developing a webmailer to your needs sitting on the popserver itself - so, the cgi has direct access to the mailboxes. When there is a mail with e.g. an attachement which is a jpg file to be shown, the quick and dirty method is to create a temporary file and an image-tag in the dynamic html-code pointing to that file.

My knowledge of perl is still minor but my phantasy is major ;) so I imagine perl parsing that file bytewise and "stream" the jpg-attachement somehow, avoiding creating a temporary file. This is a new idea I am wondering about, so, no code is written, yet. I'd appreciate statements about it.


--

there are no silly questions
killerhippy
  • Comment on avoid temporary files when building a webmailer

Replies are listed 'Best First'.
Re: avoid temporary files when building a webmailer
by Masem (Monsignor) on Nov 15, 2001 at 17:16 UTC
    It's certainly possible, see How can I use a CGI script to return an image?. Mind you, if you are discussion putting this pic into a dynamically generated page, you probably need to make sure that the CGI script handles both the page generation and the image push, and make sure that the image src points back to the script with necessary details in order to push the image out. In other words, if you want to show the mail message and the image, your script will need to be run twice.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    "I can see my house from here!"
    It's not what you know, but knowing how to find it if you don't know that's important

Re: avoid temporary files when building a webmailer
by John M. Dlugosz (Monsignor) on Nov 16, 2001 at 00:27 UTC
    As I see it, you link to a cgi instead of the jpeg, and when triggered, that code sends to stdout the exact same thing that you would have done to write the temporary, after sending the header (file type and blank line is enough, I think).

    —John

Re: avoid temporary files when building a webmailer
by khippy (Scribe) on Nov 15, 2001 at 17:59 UTC

    Excellent, thanx for the help, this will avoid problems, when building the script (headerstuff, etc.). Still unsolved is the fact from grepping the data from the file. Let me explain:
    Assumed you already can handle each mail in the mailboxfile, now there is a mail which contains a jpg attachement, which is, indeed part of the bodytext and identified by boundaries and here comes the trick: How to read *only* the attachement data from the file?


    --
    there are no silly questions
    killerhippy
      You might want to have a look at the MIME modules on CPAN. They should do what you want.

        I have looked at Mime::Tools to get an impression of the mime-tools. At the first look it seemed nice, it gives a nice surface to get access to all parts of the mail.
        But, unfortunately, I have found the following:

        ..."Use of a temp file during parsing

        Why not do everything in core? Although the amount of core available on even a modest home system continues to grow, the size of attachments continues to grow with it. I wanted to make sure that even users with small systems could deal with decoding multi-megabyte sounds and movie files. That means not being core-bound."...



        This exactly bypasses my goal, *not* to create a tempfile. BTW, there is no need to show multi-megabyte files in whatever audio or videoformats for my needs... a picture with maxsize 800x600 or so will be the top size.

        Thanx for the advice, but this is a special case, any ideas left?


        --
        there are no silly questions
        killerhippy