Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Problem in sending "tar" files as attachment using MIME::Lite module

by imp (Priest)
on Dec 20, 2006 at 06:21 UTC ( #590854=note: print w/ replies, xml ) Need Help??


in reply to Problem in sending "tar" files as attachment using MIME::Lite module

I tested this snippet locally without modification, other than substituting my email address and adding use strict/warnings/MIME::Lite.

I succesfully tested sending a mail with a tar file created by both my native tar binary and Archive::Tar. Both mails were received, and untarring the file on the other end worked fine.

The only failure I encountered was when I did not add any files to the newfile.tar. A file created with this:

perl -MArchive::Tar -e '$t = Archive::Tar->new(); $t->write("newfile.t +ar")'
Yielded the following when reading the file with tar -tf:
tar: Cannot identify format. Searching... tar: End of archive volume 1 reached tar: Sorry, unable to determine archive format.
These tests were performed on OpenBSD 3.5, perl 5.8.2, Archive::Tar 1.10, MIME::Lite 3.01. Mails were read with mutt and gmail.


Comment on Re: Problem in sending "tar" files as attachment using MIME::Lite module
Select or Download Code
Re^2: Problem in sending "tar" files as attachment using MIME::Lite module
by santhi (Monk) on Dec 20, 2006 at 07:21 UTC
    hi,

    I think problem is with creating the Tar file. I am using the code as below:
    my $tar = Archive::Tar->new(); my @filelist = ("txt.del", "txt1.del"); $tar->add_files(@filelist); $tar->write("newpart.tar", 2); my $error = $tar->error(); print "error is $error \n";
    By using the $tar->write("newpart.tar", 2); , I am getting the error as "Invalid archive directory".
    But to use the $tar->write("newpart.tar"); , the tar file size is very large.

    So which compression value can be used such that the tar file size will be less and will open without errors.

    Thank you,
    Santhi
      You could try opening the output file first, using PerlIO::gzip so that it gets compressed on output, then pass the file handle to Archive::Tar->write() -- something like this:
      use PerlIO::gzip; use Archive::tar; # ... open( my $tarfh, ">:gzip", "my_tarball.tar.gz" ); # ... $tar->write( $tarfh );
      (I haven't tried that myself, but that's what I would try.)

      UPDATE: (2010-10-18) It seems that PerlIO::gzip should be viewed as superseded by PerlIO::via:gzip. (see PerlIO::gzip or PerlIO::via::gzip).

      That error is not coming from your code snippet, correct? Is it coming from winzip (or some other extraction program) when you try to extract it? I wonder if your extraction program is barfing because it doesn't know how to handle the decompression. If you're going to compress the archive, you should name it either newpart.tar.gz or newpart.tgz. Then your extraction program may be better able to handle it or at least you've let others know the archive needs to be unzipped first. And if your mailing compressed, I wouldn't use the application/tar mime type, application/x-gtar would probably work better.

      -derby

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://590854]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-08-01 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (257 votes), past polls