This special-purpose script has been updated on Thurs Sep 13, 2001 to reflect improvements needed to make it more compatible with the ugly realities of MS Windoze OS's: the code using a shell file descriptor redirect 2>&1 has been conditional'd-out for users of non-NT systems (which are far more seriously broken). The code has now been used and tested on Win98.
Soren Andersen
Pegasus Email for Win32 is a widely used and fine zero-cost email client. It has the feature that it can load a file at run time which contains an arbitrarily large collection of email .sigs, and include these into outgoing messages randomly. In order to set it up for Pegasus to do this, one must manually create the binary "RQUOTES.PMS" file and place it one's Pegasus user directory. This file is a compiled resource file produced from a human-readable text file using the resource compiler <CITE>rescom.exe</CITE>, included in Pegasus Email.
Further steps are also required on the Pegasus menu level and although not difficult to accomplish, rigorously detailing them here is beyond the scope of this posting and OT for this Monastery. That info is available in the Pegasus documentation.
The program requires the endlessly enjoyable and useful Perl module Text::Autoformat (CPAN). Naturally as it is only relevant to the Win32 Perl user group, it also uses Win32:: modules. File::Compare is also used. The code is rough and user convenience hasn't been dealt with; lots of manual setup will be needed.
Intrepid (Soren)
#!perl -w # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # "MakePSigs.p" is a Perl-on-Win32 program for managing the auto- # generation of a random .sig compiled resource file that is used by # Pegasus Email for Win32. # Copyright (c) 2001 Soren Andersen. All Rights Reserved. # This program is Free Software and may be used, copied or modified # subject to the same terms as Perl itself. # L/M: Thu Sep 13 18:28:00 2001 # # sample invocation: # $> MakePSigs.p "soren" "E:/data/var/MBOXEN/RQUOTES.PMS" # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ use Text::Autoformat; use Win32; use Win32::FileOp; use Win32::Process; use File::Compare qw{cmp}; use strict; use vars qw{ $QuoSrc $QuoteFile $Backup $WrkDir $RPG_rsc $Whatever $ShortQFname @Msgs @Quotes $TodayNow }; use subs qw{ &EntryFormat &ErrorReport &UnDOS &ReDOS}; # DO USER CONFIGURATION OF PATHS HERE $QuoSrc = 'E:/data/textfile/email_sigs/Philosophic_random_src.txt'; $WrkDir = 'E:/Pegasus/Resource'; # "Rquotes.pms" goes where your Pegasus user files live: $RPG_rsc = ($ARGV[1])? $ARGV[1] : 'G:/Pegasus_user/Rquotes.pms'; # DONE WITH USER CONFIGURATION $Whatever = ''; my $pegasus_user = ($ARGV[0])? lc $ARGV[0] : 'default'; ($QuoteFile,$Backup) = ( ReDOS($WrkDir).'\Rquotes.'.$pegasus_user, ReDOS($WrkDir).'\Rquotes.'.$pegasus_user .q[BU]); open(QRAW, qq[<$QuoSrc]) or die autoformat(<<OUTPUT There is something wrong, I could not open() the quotations text source file "$QuoSrc", are you sure it is really there? - "$!" OUTPUT , {all =>1}); sub UnDOS { my $pathspec_expression = shift; $pathspec_expression =~s@\\@/@g; return $pathspec_expression; }; sub ReDOS { my $pathspec_expression = shift; $pathspec_expression =~s@/@\\@g; return $pathspec_expression; }; $ShortQFname = UnDOS( Win32::GetShortPathName( UnDOS($QuoteFile) ) ); print STDERR qq[\n DIAGN: "$ShortQFname" is file name\n]; my $block = 0; my $current = []; while (<QRAW>) { if (/^\<\<$/ ) { $Quotes[$block++] = $current; undef $current; (eof)? last:next; } push @$current, $_; } close ( QRAW ); foreach my $rand_sig (@Quotes) { print STDERR qq[\n], &EntryFormat($rand_sig); } print STDOUT qq{\n}, '-' x 58, qq{\nWould you like to add these}, qq{ quotes to the Random Philosopical Quote (RPQ) file?\n}; if (<STDIN> =~/Y(?:es)?/i) { CopyEx($QuoteFile => $Backup, FOF_ALLOWUNDO | FOF_FILESONLY) if -e $QuoteFile; open RPQ, qq[> $QuoteFile] or die $!; $TodayNow = localtime(time); print RPQ<<FINI; # file automatically generated, last revision on $TodayNow headers off # Ignore this command symbols off # Ignore this command. FINI foreach my $rand_sig (@Quotes) { print RPQ qq[\n], &EntryFormat($rand_sig); } close( RPQ ) or die $!; chdir "$WrkDir" or die qq[\nCould not cd into wrkng Peg dir "$WrkDir":\n$!]; if (Win32::IsWinNT()) { (my $piD = open RPQCC, ReDOS($WrkDir).q[\Rescom.exe]. qq[ $ShortQFname 2>&1 |]) or die qq[We had pipe-open() trouble. ], qq[Could not open "rescom.exe":], qq[\n$!]; push @Msgs, qq[\n\nMessages from the resource compiler:\n\n]; if (defined $piD) { while (<RPQCC>) { push @Msgs, ' '. $_; $Whatever = $1 if (m@Created\s resource\s file\s ([A-Z]:/.+/Resource/RQUOTE.+\.rsc) \:@xi); } } close( RPQCC ) or warn qq[Cannot close the pipe-handle?!:\n $?]; } elsif (Win32::GetOSVersion()) # return values: Win9x 1, WinNT 2 { select STDERR; $|++; select STDOUT; $|++; my ($spawnd, $pid, $exitcode); Win32::Process::Create($spawnd, q[RESCOM.exe], "RESCOM $ShortQFname -w -a", 0, CREATE_NEW_CONSOLE, ".") || die ErrorReport(); if ( $pid = sprintf(q[%#8X],$spawnd -> GetProcessID()) ) { print STDERR qq[\nThe RESCOM.EXE process was successfully ], qq[started and is running as PID $pid\n]; $spawnd -> Wait(3000); $Whatever = q[RQUOTE~1.RSC]; $spawnd -> GetExitCode( $exitcode ); my $rverb = substr (Win32::FormatMessage($exitcode << 256), 0, -2); $rverb = ($rverb)? $rverb : q[OK]; print STDERR qq[\n Exit status for the RESCOM process: ], ( $exitcode << 256 ), qq[ ("${rverb}")\n]; } else { warn autoformat( qq[\nThe RESCOM.EXE process was ]. qq[ not started right, no pid returned ...] ); } } print STDERR @Msgs,qq[Done compiling, did it go satisfactorily?\n]; if (<STDIN> =~/Y(?:es)?/i and $Whatever) { $Win32::FileOp::ProgressTitle = qq[Copying Pegasus resource file $Whatever to user dir]; CopyConfirm("$Whatever" => "$RPG_rsc") or die qq[Copy .RSC to Pmail user dir failed:\n$^E \n($!)]; if ( cmp( $Whatever,$RPG_rsc ) ) { warn qq[Copy .RSC to Pmail user dir .PMS failed:\n], qq[the files are not the same]; } else { print STDERR qq[\nDone! -- $RPG_rsc is ], int(-M $RPG_rsc), qq[ days old.\n]; } } else { print STDERR qq[\nYou've elected to abort the procedure? OK.\n]; exit 2; } } # END IF STDIN =~"yes" exit 0; # ================ SUBS =================== sub EntryFormat { my $sigquote = shift; my @sigquote = do { split qq[\n],autoformat(join(q[ ],'',@$sigquote), { all =>1, left =>5, right =>68} ); }; @sigquote = map{ s@\"@'\"'@ge if length >= 0; $_ .= '\n' if length >= 0; if ($_ !~/^$/) {$_;} else {'';} } @sigquote; @sigquote = map{$_ = qq["$_",\n];} @sigquote; my $final = join '', @sigquote; my $entry=<<DONEDEAL; text x { $final }; DONEDEAL return $entry; } sub ErrorReport{ print Win32::FormatMessage( Win32::GetLastError() ); } =pod =head1 Name MakePSigs =head1 Synopsis C<perl MakePSigs.p [Pegasus login name] [pathspec for outputfile]> =over 3 The Pegasus Email login name is optional; if not used, the script will paste the suffix ".default" onto the end of generated filenames. You'd want to name the source textfile (see below) appropriately, then, B<before> running the script. =back =head1 Description B<Pegasus Email for Win32> is a widely used and fine zero-cost email client. It has the feature that it can load a file at run time which contains an arbitrarily large collection of email .sigs, and include these into outgoing messages randomly. In order to set it up for Pegasus to do this, one must manually create the binary "RQUOTES.PMS" file and place it one's Pegasus user directory. This file is a compiled resource file produced from a human-readable text file using the resource compiler F<rescom.exe>, included in "Pegasus Email for Windows." Further steps are also required on the Pegasus menu, namely setting a signature choice with the characters `B<~!>' (B<tilde-bang>) at the place where you want the randomely-chosen quote to be inserted. See the Pegasus Email for Windows documentation. The program requires the endlessly enjoyable and useful Perl module F<Text::Autoformat> (CPAN). Naturally as it is only relevant to the Win32 Perl user group, it also uses F<Win32::> modules. F<File::Compare> is also used. The code is rough and user convenience hasn't been dealt with much; some attention to manual setup will be needed. =head2 The Source file Format The script reads in from a source file, a text file with a format along these lines: "The reasonable man adapts himself to the world ... the unreasonable man persists in trying to adapt the world to himself +." "Therefore, all progress depends on the unreasonable man." -- George Bernard Shaw << "Kindness is the flower of strength." -- Jose Marti, Hero of Cuban Independence << The example file above has been indented in this POD documentation to preserve formatting; in actual use there would be no left margin. The E<lt>E<lt> characters on a line alone is the delimiter between quotes. Make sure the last quote in the file is followed by the delimiter I<or the script will break>. =head2 from Pegasus header: ## Compile this source using ResCom.exe, by issuing the ## command "ResCom RQUOTES.R", then copy the resulting ## RQUOTES.RSC file into your home mailbox as RQUOTES.PMS. ## ## So, the sequence of commands looks like this: ## ## C:\PMAIL> rescom rquotes.r ## C:\PMAIL> copy rquotes.rsc f:\mail\9000001\rquotes.pms =head1 AUTHOR Soren Andersen E<lt>libertador@flashmail.comE<gt> =for html <A HREF="mailto:libertador@flashmail.com">libertador@flashmail.com</A> =head1 COPYRIGHT Copyright (c) 2001 Soren Andersen. All Rights Reserved. This program is Free Software and may be used, copied or modified subject to the same terms as Perl itself. =cut
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |