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

I am trying to email a letter with many attachments to a client.

The program does attach the files, and when I click on them, Netscape correctly shows the content.

The problem is then I click View Source the contents of ALL the files is listed.

So, suppose I am attaching 6 files to an email, each file is rendered ok when viewing in Netscape. However, when I view the source, I get the total contents of ALL SIX FILES.

Is there anyway I can stop this merging of files using MIMELITE? Here is the code that I am using.

Thank you!

Robert

sub EmailClient { my ($file, $dir, $list) = @_; my $msg; my $cover; my @list; my $data; my $bf; my $type; # 9/6/01 $today = `date '+%m/%d/%y'`; $today =~ s/\n//; $cover = "The email body message Thank you, Corporation, Inc."; ### Create a new multipart message: $msg = MIME::Lite->new( From =>'My address <webmaster@company.com>', To =>'robert@idi.net', Subject =>"Your Message", Type =>'text/plain', Data =>"$cover" ); ### Add parts (each "attach" has same arguments as "new") # Attach the HTML document if the email is not empty # Compress and attach the files # $list is a comma separated string of filenames like this: # file1,file2,file3,....fileN @list = split (/,/, $list); foreach $bf (@list) { undef $/; open (ATTACH, "$dir/$bf") || die "Cant open file $dir/$bf\n\n"; $data = <ATTACH>; close (ATTACH); # If file is an HTML file, set type to text/html # If it is an XML file, set type to text/plain if ($bf =~ /\.xml/i) { $type = 'text/plain'; } else { $type = 'text/html'; } $msg->attach ( Type =>"$type", Disposition =>'attach', Data =>"$data", Filename =>"$bf" ); } # Send the message $msg->send(); }

Replies are listed 'Best First'.
Re: Why is MIME::Lite not processing my attachments properly?
by idnopheq (Chaplain) on Sep 24, 2001 at 21:14 UTC
    UPDATE: oops. I meant to quote Is there anyway I can stop this merging of files using MIMELITE?

    IIRC, this is how MIME works. It's all essentally text, with MIME boundaries between component parts. A MIME-capable client will render the attachment files as seperate with pretty little icons, but viewing them raw will show it all "as <insert your deity here> intended".

    However, maybe I'm missing something as I often do ( as it is Monday right now where I come from ). So, what is MIME::Lite doing or not doing that you require?

    HTH
    --
    idnopheq
    Apply yourself to new problems without preparation, develop confidence in your ability to to meet situations as they arrise.

      Thanks for responding.

      Suppose I have 4 files:

      file1 = "Red"
      file2 = "Blue"
      file3 = "Green"

      When I run my program, I get an email with 3 attachments on it.

      When I open Attachment 1, it correctly says "Red"
      When I open Attachment 2, it correctly says "Blue", etc.

      However when I view the source for Attachment 1, it reads "RedBlueGreen"...IE the contents of all 3 files. So how can I get the View Source to only read "Red" and not "RedGreenBlue" ???

      Thanks!

      Robert

        Ah! The "View Soure" capability likely does not employ any kind of MIME processing. This would make it similar to a "raw" output.

        I tried this on my Mozilla Mail client, and indeed I saw all of the attachments as you describe. IMHO this is more to do with the browser/client than the MIME protocol. In fact, back in the days when I used GNUS in EMACS to read my email, it behaved this way by default.

        HTH
        --
        idnopheq
        Apply yourself to new problems without preparation, develop confidence in your ability to to meet situations as they arrise.

        Actually, I'm afraid this is not a Perl question. Is Mozilla written in C, I think?

        What you're seeing is exactly what (Mozilla thinks) you're asking for, even if it isn't what you meant to ask for. The "source" you're seeing is the "source of this message," not the "source of this part." You're viewing the MIME source, which (as it happens) is 100% identical to the typical text/plain source, and 99% the same as typical text/html source, but can potentially be quite different - e.g. a base64-encoded text/plain message is entirely illegible (to me!) in source form.

        The only way to change this, AFAIK, would be to change the behaviour of the MUA - i.e. Netscape. Since you can't directly change Netscape, it becomes a C issue -- you'd have to contribute to Mozilla and add an option such as "view source of only this part."

        In the alternative, save a copy of the part (i.e. in this case attachment) to your desktop, open it back up, and view/source on it.

        Appendix: Can anyone give a counter-example of a multipart message whose view/source does show only a single part? E.G. does it view only a single part if you read by way of a window viewing only that single part, or some other behaviour I don't know about? I'm afraid Netscape/Mozilla mail steadfastly refuses to work for my mailbox, so I can't confirm 100% that there's not something like this hidden in the UI somewheres...

Re: Why is MIME::Lite not processing my attachments properly?
by Maclir (Curate) on Sep 25, 2001 at 07:37 UTC
    Disclaimer: I would not trust Netscape to correctly display Mime attachments using "view source". (What version of Netscape, and on what platform, are you using?)

    Have you tried verifying the correct presentation of your attachments using another MUA? Because I assume what you are wanting to verify is that the recipients of your complete mail messages will see the the text of the main part of your message, and the fact that there are several "mimed" attachments, each of which they can view or deal with as they wish. If the message appears to be structured correctly using a common MUA, then you have what you want.

    For example, send it to a dummy hotmail account, and look at your message that way. You can set the hotmail options to display the complete mail headers in full detail, including all mime stuff.