home *** CD-ROM | disk | FTP | other *** search
- Xref: wupost comp.lang.perl:7228 alt.sources:3873
- Path: wupost!uunet!island!daniel
- From: daniel@island.COM (Daniel Smith - innovate or die...)
- Newsgroups: comp.lang.perl,alt.sources
- Subject: pearmail.pl - replacement for tarmail
- Summary: handle large files/binary data easily by mail
- Keywords: perl archiving mail encoding
- Message-ID: <4460@island.COM>
- Date: 20 Aug 91 21:31:58 GMT
- Followup-To: comp.lang.perl
- Organization: Island Graphics, Marin County, California
- Lines: 415
-
-
- pearmail 1.1, August 20, 1991
-
-
- What this is:
-
- pearmail (uses perl to encode and archive mail, also rhymes with
- "airmail") is a replacement for tarmail. You can use it to safely send
- any data to others via email. By default, pearmail makes a tar file,
- uuencodes that, and splits that into separate mail messages. The recipient
- then saves these messages to individual files, and runs "pearmail -extract"
- on them. The recipient does not have to save the messages to consecutive
- filenames, pearmail figures out the right order. There is also a "-helpthem"
- option, so that the pearmail script gets sent with your files. This makes
- it easy for your recipient to unpack them, and is an easy way to propagate
- this script to perl installations everywhere :-)
-
-
- What to try:
-
- Mail yourself some files. This line will work in most shells:
-
- cd $HOME; pearmail $USER "backup of dot files" .[a-z]*
-
- send some files to a friend, and give them the pearmail script:
-
- pearmail -helpthem some_friend "here are those files" some_files
-
- extracting:
-
- When you receive mail, save all of the letters to individual files.
- If you use mush, you can do something like:
-
- pick -s dot files | s -s
-
- to some empty directory, and then in a shell:
-
- pearmail -extract *
-
- for additonal help, run "pearmail" by itself.
-
-
- If you make improvements to pearmail, SEND ME DIFFS... I've made
- this very easy to do by including my address in the help screen. This
- has the potential to handle a lot of different formats in a consistent
- manner, making it easier for end users to unpack things.
-
- If you need to do any customization, look at the leading section of
- the script. Also, if you do customizations, such as using atob, abe, zip,
- etc., use the -helpthem option so that people receiving your mail have an
- easy way to deal with your scheme.
-
- enjoy!
-
- Daniel
-
- ------- snip --- cut ----- tear ----- chop -----
- #!/bin/sh
- # This is a shell archive (shar 3.10)
- # made 08/20/1991 21:30 UTC by daniel@bermuda
- # Source directory /usr/bermuda/people/daniel/src/perl
- #
- # existing files WILL be overwritten
- #
- # This shar contains:
- # length mode name
- # ------ ---------- ------------------------------------------
- # 2152 -rw-r--r-- README.pearmail
- # 6366 -rwxr-xr-x pearmail
- #
- touch 2>&1 | fgrep '[-amc]' > /tmp/s3_touch$$
- if [ -s /tmp/s3_touch$$ ]
- then
- TOUCH=can
- else
- TOUCH=cannot
- fi
- rm -f /tmp/s3_touch$$
- # ============= README.pearmail ==============
- echo "x - extracting README.pearmail (Text)"
- sed 's/^X//' << 'SHAR_EOF' > README.pearmail &&
- X
- X
- X pearmail 1.1, August 20, 1991
- X
- X
- X What this is:
- X
- X pearmail (uses perl to encode and archive mail, also rhymes with
- X"airmail") is a replacement for tarmail. You can use it to safely send
- Xany data to others via email. By default, pearmail makes a tar file,
- Xuuencodes that, and splits that into separate mail messages. The recipient
- Xthen saves these messages to individual files, and runs "pearmail -extract"
- Xon them. The recipient does not have to save the messages to consecutive
- Xfilenames, pearmail figures out the right order. There is also a "-helpthem"
- Xoption, so that the pearmail script gets sent with your files. This makes
- Xit easy for your recipient to unpack them, and is an easy way to propagate
- Xthis script to perl installations everywhere :-)
- X
- X
- X What to try:
- X
- X Mail yourself some files. This line will work in most shells:
- X
- X cd $HOME; pearmail $USER "backup of dot files" .[a-z]*
- X
- X send some files to a friend, and give them the pearmail script:
- X
- X pearmail -helpthem some_friend "here are those files" some_files
- X
- X extracting:
- X
- X When you receive mail, save all of the letters to individual files.
- X If you use mush, you can do something like:
- X
- X pick -s dot files | s -s
- X
- X to some empty directory, and then in a shell:
- X
- X pearmail -extract *
- X
- X for additonal help, run "pearmail" by itself.
- X
- X
- X If you make improvements to pearmail, SEND ME DIFFS... I've made
- Xthis very easy to do by including my address in the help screen. This
- Xhas the potential to handle a lot of different formats in a consistent
- Xmanner, making it easier for end users to unpack things.
- X
- X If you need to do any customization, look at the leading section of
- Xthe script. Also, if you do customizations, such as using atob, abe, zip,
- Xetc., use the -helpthem option so that people receiving your mail have an
- Xeasy way to deal with your scheme.
- X
- X enjoy!
- X
- X Daniel
- X
- X daniel@island.com daniel@world.std.com dansmith@well.sf.ca.us
- XDaniel Smith, Island Graphics, 94903, CA (415) 491 0765 x 250(w), 491 0402(fax)
- X Disclaimer: written by a highly caffeinated mammal
- X$|=1;for("..."," hacker"," perl"," a","just"){print $l=$_.$l,"\015";sleep 1;}
- SHAR_EOF
- chmod 0644 README.pearmail || echo "restore of README.pearmail fails"
- if [ $TOUCH = can ]
- then
- touch -am 0820142991 README.pearmail
- fi
- # ============= pearmail ==============
- echo "x - extracting pearmail (Text)"
- sed 's/^X//' << 'SHAR_EOF' > pearmail &&
- X#! /usr/bin/perl
- X#
- X# pearmail - use perl to send and extract uuencoded, t'archived mail
- X#
- X# Daniel Smith, daniel@island.com, July, August 1991
- X
- X&usage unless @ARGV;
- X@command_line_args = @ARGV; # for -helpthem
- X
- X# things to customize
- X$tmp_dir = "/tmp";
- X$how_we_mail = "Mail -s";
- X$how_we_package = "tar cvf -";
- X$how_we_compress = "compress";
- X$how_we_encode = "uuencode pearmail.tar.Z";
- X$how_we_decode = "uudecode";
- X$how_we_split = "split -700 - $tmp_dir/pearmail.";
- X
- X# more portable...
- X#$how_we_extract = "cat pearmail.tar.Z | uncompress | tar -xvf - ";
- X$how_we_extract = "zcat pearmail.tar.Z | tar xvf - ";
- X
- X# set up the way we'll process our options
- X%options = (
- X '-helpthem', '&set_help',
- X '-extract', '&set_extract',
- X '-x', '&set_extract',
- X '-e', '&set_extract',
- X '-h', '&usage',
- X '-help', '&usage',
- X '-usage', '&usage',
- X);
- X
- X# *anything* to avoid "if elsif elsif" ad infinitum :-)
- Xwhile ($_ = shift @ARGV) {
- X if (/^-/) {
- X eval ($options{$_}) || print "no such option: $_\n";
- X } else {
- X push (@our_args, $_);
- X }
- X}
- X
- Xif ($we_are_extracting) {
- X &arrange_filenames;
- X &do_extract;
- X exit;
- X}
- X
- X# otherwise, we're sending something...
- X
- Xif (($#our_args + 1) < 3) {
- X print "not enough arguments, run \"pearmail -usage\" for help...\n";
- X exit 0;
- X}
- X
- X$recipient = shift @our_args;
- X$subject = shift @our_args;
- X
- Xif ($send_them_help) {
- X &send_myself;
- X}
- X
- X# now all the rest of @our_args are files that we are sending
- X
- X$how_to_send = join ('|', $how_we_package." @our_args", $how_we_compress,
- X $how_we_encode);
- X
- Xopen (SENDPIPE, "$how_to_send | split -700 - $tmp_dir/pearmail.$$.|") ||
- X die "can't set up pipe!: $!\n";
- Xwhile (<SENDPIPE>) {
- X print; # output of pipe (tar) commands...
- X}
- Xwait;
- X
- X@files_we_send = <$tmp_dir/pearmail.$$.*>;
- X$cur_part = 1;
- X$total = ($#files_we_send + 1);
- X@fname_exts = 'xaa'..'xdz';
- X($fname_subject = $subject) =~ tr/ \t":;`'/_/s;
- Xwhile ( <$tmp_dir/pearmail.$$.*> ) {
- X $full_subject = "$subject part $cur_part of $total";
- X open (MAILPIPE, "|$how_we_mail \"$full_subject\" $recipient")
- X || die "can't set up pipe!: $!\n";
- X open (STUFF_TO_MAIL, $_);
- X print MAILPIPE <<"PREAMBLE";
- X
- XPEARMAIL_HEADER_START
- X This is part $cur_part of $total
- X
- X This file was created with pearmail, and contains an archive
- X of:
- X @our_args
- X
- X Save this part, and any other parts, to separate files (it won't
- X matter what names you give the files), and run:
- X
- X pearmail -extract <filenames>
- X
- X on them. You will then have the decoded contents of the archive.
- X
- X SUBJECT: $subject
- X FILENAME: $fname_subject.$fname_exts[$cur_part - 1]
- X
- X The steps involved with creating the entire archive were:
- X $how_to_send
- XPEARMAIL_HEADER_END
- XPREAMBLE
- X
- X print MAILPIPE "PEARMAIL_DATA_START\n";
- X print MAILPIPE <STUFF_TO_MAIL>;
- X print MAILPIPE "PEARMAIL_DATA_END\n";
- X $cur_part++;
- X close (STUFF_TO_MAIL);
- X unlink $_ || die "can not rm tmp files: !$\n";
- X}
- X
- X
- Xsub send_myself {
- X open (MYSELF, $0) || die "can't open myself!: $!\n";
- X open (MAILME,
- X "|$how_we_mail \"pearmail script - sent with: $subject\" $recipient")
- X || die "can't set up pipe!: $!\n";
- X
- X while (<MYSELF>) {
- X if ($. == 6) {
- X print MAILME "
- X# This script was automatically generated by $ENV{'USER'}
- X# running this command from $ENV{'SHELL'}:
- X# $0 @command_line_args
- X#
- X# if this was mailed to you, and you are wondering what to do, follow
- X# these simple steps:
- X#
- X# 1) save this message without any headers (or trim them off later). The
- X# very first line should say \"#! /usr/bin/perl\". Save this to the
- X# filename \"pearmail\".
- X#
- X# 2) make this an executable script by entering \"chmod +x pearmail\"
- X# from a shell.
- X#
- X# 3) if someone sent you some files along with this script via mail,
- X# save the messages out to separate files, and run the command
- X# \"pearmail -extract <the filenames>\" on them.
- X#
- X";
- X }
- X print MAILME;
- X }
- X}
- X
- Xsub set_help {
- X $send_them_help = "yep";
- X}
- X
- Xsub set_extract {
- X $we_are_extracting = "yep";
- X}
- X
- Xsub arrange_filenames {
- X if ($#our_args < 0) {
- X die "you haven't told me which files to extract from...\n";
- X }
- X foreach $raw_file (@our_args) {
- X open (RAW, $raw_file) || warn "cannot open $raw_file: $!\n";
- X while (<RAW>) {
- X next unless /PEARMAIL_HEADER_START/;
- X last;
- X }
- X if (eof (RAW)) {
- X print "can't find pearmail header in $raw_file\n";
- X } else {
- X while (<RAW>) {
- X if (/PEARMAIL_HEADER_END/) {
- X last;
- X }
- X if (/FILENAME: /o) {
- X chop ($_);
- X ($skip, $all_raw_files{$raw_file}) =
- X split (/ /, $_);
- X last;
- X }
- X }
- X }
- X }
- X foreach $old_name (keys %all_raw_files) {
- X print "$old_name becomes $all_raw_files{$old_name} ....\n";
- X close RAW;
- X rename ($old_name, $all_raw_files{$old_name});
- X }
- X}
- X
- Xsub do_extract {
- X $| = 1;
- X #open (DEBUG_FILE, "> debug") || die "can't set up debug file!: $!\n";
- X open (DECODE_PIPE, "|$how_we_decode") ||
- X die "can't set up pipe!: $!\n";
- X
- X foreach $workfile (sort (values %all_raw_files)) {
- X print "now working with $workfile\n";
- X
- X open (CUR_WORK_FILE, $workfile) ||
- X die "can't open $workfile!: $!\n";
- X while (<CUR_WORK_FILE>) {
- X next unless /PEARMAIL_DATA_START/o;
- X last; # ok, now we want the next line...
- X }
- X while (<CUR_WORK_FILE>) {
- X last if /PEARMAIL_DATA_END/;
- X print DECODE_PIPE;
- X # print DEBUG_FILE;
- X }
- X close (CUR_WORK_FILE);
- X }
- X
- X # very important to have this...flush out the end of the tar,,,
- X close (DECODE_PIPE);
- X
- X open (EXTRACT_PIPE, "$how_we_extract|") ||
- X die "can't set up pipe!: $!\n";
- X while (<EXTRACT_PIPE>) {
- X print;
- X }
- X}
- X
- Xsub usage {
- X print "Usage: pearmail [options] person@somewhere \"Subject\" files.
- X
- Xpearmail is used to send groups of files to someone. By default,
- Xa tar file is created, uuencoded, and sent in parts through mail.
- XThe recipient then saves those parts to separate files (with any names
- Xthey want), and runs pearmail -extract on them.
- X
- Xoptions:
- X -helpthem forward a copy of this script
- X -extract unarchive the files
- Xexamples:
- X pearmail -helpthem daniel@island.com \"diffs to pearmail\" diffs
- X pearmail gumby@claytown.com \"blockhead jokes\" bjokes
- X
- X The first example sends the files to someone, and also sends this
- X script, giving you an easy way to give this to them.
- X
- X The second example is everyday usage; sending to some one who already
- X has pearmail.
- X
- X When someone gets their mail, they may save the parts to any file
- X names they wish. They then run \"pearmail -extract files\" to get
- X the archive extracted.
- X";
- X exit 0;
- X}
- X__END__
- SHAR_EOF
- chmod 0755 pearmail || echo "restore of pearmail fails"
- if [ $TOUCH = can ]
- then
- touch -am 0820141391 pearmail
- fi
- exit 0
- --
- daniel@island.com daniel@world.std.com dansmith@well.sf.ca.us
- Daniel Smith, Island Graphics, 94903, CA (415) 491 0765 x 250(w), 491 0402(fax)
- Disclaimer: written by a highly caffeinated mammal
- "fgrep is a dog, and a mad one at that." - Tom Christiansen
-