Converting between .mailrc and MH aliases

Converting between .mailrc and MH aliases

Post by Curtis N. Bingh » Thu, 04 May 1995 04:00:00



I wrote a little script which will convert between mh aliases format
and the bsd format of the .mailrc file.  It is simple, converts both
ways and tries to do some error checking.  Seems to work on this end.
(I'm sure someone will reply with a 1 liner which will do all this and
more! :-)

---Shnip 'ere -----------------------------
#!/msrc/apps/bin/perl
# File:  aliasconv

# On: Tue May  2 20:10:01 1995
# Description:
#   This is a simple script that will make sure the bsd and mh mail
#   aliases are the same.
#   By default, the script will convert the mh aliases file
#   (~/Mail/aliases) to bsd format (~/.mailrc).  If given the
#   command-line argument -bsd, it will convert the bsd mail aliases
#   to mh format.
# Todo:
#   Add a -help option.

# Get the user's home directory:

$home = $ENV{'HOME'};

# Get the root mh directory (~/mh-Mail in my case, ~/Mail in most
# others)
$mh_dir = $home . '/mh-Mail';

if(!-d $mh_dir)
{
    $mh_dir =~ s/mh-//;

Quote:}

#print "$mh_dir\n";

die "MH directory ~/Mail cannot be found" unless (-d $mh_dir);

# If the first argument is either '-bsd' or 'bsd', then we are
# converting from mh aliases to bsd .mailrc:
if ($ARGV[0] eq '-bsd' ||$ARGV[0] eq 'bsd' ){
    $conv2mail = 0;

Quote:}

else {
    $conv2mail = 1;

Quote:}

if ($conv2mail)
{
    $from_alias_file = $mh_dir . '/aliases';
    $to_alias_file = $home . '/.mailrc';
Quote:}

else
{
    $from_alias_file = $home.'/.mailrc';
    $to_alias_file = $mh_dir.'/aliases';

Quote:}

print "Converting \n\t$from_alias_file\nto\n\t$to_alias_file.  \nProceed (y/n)? ";
$ans = <STDIN>;
chop($ans);
$ans =~ tr/Y/y/;
# Seems that there ought to be a better way to do this:
die "Aborting!" unless ($ans eq 'y');

die "Can't open $from_alias_file" unless
    open(FROM_ALIAS_FILE,$from_alias_file);

die "Can't open $to_alias_file" unless
    open(TO_ALIAS_FILE,">".$to_alias_file);

print "Working. . . .";

while(<FROM_ALIAS_FILE>)
{
    if($_ eq "# Local eval hooks:\n"){
        # toss the rest:
        while (<FROM_ALIAS_FILE>){}
        last;
    }
    if($conv2mail){
        $_ =~  s/^([A-Za-z_-]*)\:/alias $1/g; }
    else {
        $_ =~  s/^alias ([A-Za-z_-]*)/$1\:/g; }
    print TO_ALIAS_FILE "$_";

Quote:}

if($conv2mail){
    # Add some stuff to the .mailrc that will allow emacs to re-read
    # these aliases without having to be restarted:
    print TO_ALIAS_FILE "\n\n\n# Local eval hooks:\n";
    print TO_ALIAS_FILE "# The following will cause emacs to re-read these aliases right away:\n" ;
    print TO_ALIAS_FILE "# (setq mail-aliases t)  <--- put cursor here, & hit C-x C-e\n\n";
    print TO_ALIAS_FILE "# For version 18, use the eval: (make-local-variable 'write-file-hooks)\n";
    print TO_ALIAS_FILE "# For emacs, remove the final nil, for 'append'\n";
    print TO_ALIAS_FILE "# or use this form:\n";
    print TO_ALIAS_FILE "#      (add-hook 'local-write-file-hooks\n";
    print TO_ALIAS_FILE "#                 (function \n"; #
    print TO_ALIAS_FILE "#                    (lambda () \n"; #
    print TO_ALIAS_FILE "#                       (setq mail-aliases t) nil nil)))\n";
    print TO_ALIAS_FILE "\n# Local Variables:\n";
    print TO_ALIAS_FILE "# eval: (add-hook 'local-write-file-hooks \n";
    print TO_ALIAS_FILE "           (function \n"; #
    print TO_ALIAS_FILE "              (lambda () (setq mail-aliases t) nil nil)))\n";
    print TO_ALIAS_FILE "# End:\n";           #

Quote:}

close (FROM_ALIAS_FILE);
close (TO_ALIAS_FILE);

print "done\n";

--
___________________________________________________________________________

Research Scientist |  Battelle Boulevard M/S K1-87  |  (509) 375-6631 FAX  |
     KB7YAM        |     Richland, WA  99352        |  (509) 372-4726      |
     http://www.emsl.pnl.gov:2080/people/bionames/bingham_cn.html

             "Common sense?  No, we don't allow that here."
       "Fortran is every bit as dead as the Amiga" -- Jim Blinn

 
 
 

Converting between .mailrc and MH aliases

Post by Bill Wohle » Fri, 12 May 1995 04:00:00



Quote:>I wrote a little script which will convert between mh aliases format
>and the bsd format of the .mailrc file.
>(I'm sure someone will reply with a 1 liner which will do all this and
>more! :-)

  OK, you're on!  Mine only goes from .mailrc to aliases though.

alias mkalias="sed -e /^set/d -e /^unset/d -e /^ignore/d -e 's/alias [^    ]*/&:/' -e 's/^alias //' -e 's/#/;/' ~/.mailrc >| ~/mail/aliases"

  Now that I look at it, I see it could be shortened further...
  (That's a SPC and TAB in the character range, by the way.)
--

Worldtalk Corporation           ph: +1-408-399-4015  fax: +1-408-399-4013
                                Maintainer of comp.mail.mh
Say it with MIME.               and news.software.nn FAQs.

 
 
 

1. announce: script for converting addressbook to mailrc

I'm sure many people have done this before, but I couldn't find it
anywhere, so thought I'd post my solution for converting pine addressbooks
to the .mailrc format.

barney

#!/usr/local/bin/perl
#
# Time-stamp: "98/05/21 16:57:19 bdalton"
#
# Copyright (C) 1998 Barney Dalton
#
# pine2mailrc - converts pine addressbook to mailrc format
#
# usage : pine2mailrc
# input : ~/.addressbook (hard coded)
# output: stdout pine aliases in .mailrc format

$addressin=$ENV{"HOME"}."/.addressbook";

if (!open(ADDRESSIN, $addressin))
{
    print "\ncould not open $addressin\n";
    exit 1;

while (<ADDRESSIN>)
{
    chomp;


{
    while($entry =~ s/^   //) #continuation lines

    if ($entry !~ s/^\#/# /) #if its not a comment
    {
        ($nickname, $fullname, $emailaddress, $fcc, $comments) = split /\t/, $entry;
        $emailaddress =~ s/\"//;
        if ($emailaddress =~ s/^\((.*)\)$/\"$1\"/) # if group of emails
        {
            $emailaddress =~ s/,/\" \"/g; #subst commas for " "
        }
        else
        {$emailaddress= "\"" . $emailaddress . "\"";} # surround with quotes
        print "alias $nickname $emailaddress\n";
        if ($fullname ne ""){print "\# Fullname=$fullname\n";}
        if ($comments ne ""){print "\# Comment=$comments\n";}
        if ($fcc ne ""){print "\# Fcc=$fcc\n";}

    }
    else #comment
        {print "$entry\n";}

2. CD-ROM Recorders

3. How to read UNIX ~/.mailrc aliases?

4. Arkanoid

5. Sun/GNU .mailrc alias/group extensibility

6. newest handheld pc

7. .mailrc aliases - how to quote?

8. Newsgroup Permision - Atari St

9. Comments after aliases in .mailrc?

10. aliases in .mailrc don't work in Mailtool.

11. How can I update aliases in .mailrc ?

12. Alternate aliasing (.mailrc) file ?

13. Another Simple (?) Question regarding Aliases in .Mailrc