[comp.mail.elm] using my .mailrc file as my .elmrc file

kghosh@magnus.acs.ohio-state.edu (Kaushik Ghosh) (06/19/91)

Thanx in advance

Kaushik

brendan@cs.widener.edu (Brendan Kehoe) (06/20/91)

I just put this together; given your .mailrc, it'll generate an elmrc
and an aliases.text with corresponding information. It's invoked with:
  ./mailrc2elmrc < .mailrc

resulting in two files, `elmrc-new' and `aliases.text-new'.

Any fixes/suggestions/etc are more than welcome--I'm sure I missed something.

-- cut --
#!/bin/perl
#
# mailrc2elmrc v1.0 - by Brendan Kehoe (brendan@cs.widener.edu)
#
# 1.0 - 06/19/91 - original version
#
$alias_file = "aliases.text-new";
$elmrc_file = "elmrc-new";

open(ELMRC, ">" . $elmrc_file) || die "Couldn't open $elmrc_file: $!\n";
print ELMRC "# This elmrc was generated by mailrc2elmrc.\n";

while (<>) {
    /^alias[ \t]+([^ \t]*)[ \t]+(.*)/ && do { $alias{$1} = $2; $had_a = 1; };
    /^group[ \t]+([^ \t]*)[ \t]+(.*)/ && do { $group{$1} = $2; $had_g = 1; };
    /^ignore[ \t]+(.*)/ && do { $ignore[$num_ignores++] = $1; };
    /^set[ \t]+(.*)/ && do { &set_line($1); };
}

if ($hold ne 1) {
    print ELMRC "#\n# should the default be to keep unread messages in the incoming mailbox?\n";
    print ELMRC "alwayskeep = ON\n";
}

if ($num_ignores > 0) {
    print ELMRC "#\n# enable the weedout list to be read\nweed = ON\n";
    print ELMRC "# what headers I DON'T want to see, ever.\nweedout = ";
    for ($i = 0; $i < $num_ignores; $i++) { $big_ignore .= $ignore[$i]; }
    $width = 10;
    foreach $header (sort (split(/ /, $big_ignore))) {
	$width += (length($header) + 3);
	if ($width >= 78) {
	    print ELMRC "\n          ";
	    $width = 13 + length($header);
	}
	$header =~ tr/A-Z/a-z/;
	print ELMRC "\"$header\" ";
    }
    print ELMRC "\n          \"*end-of-user-headers*\"\n";
}
close(ELMRC);

if ($had_a || $had_g) {
    open(ALIASES, ">" . $alias_file) || die "Couldn't open $alias_file: $!\n";
    print ALIASES "# This file was generated by mailrc2elmrc.\n";
    print ALIASES "# It must be named aliases.text in your .elm directory\n";
    print ALIASES "# for the `newalias' command to initialize these aliases.\n#\n";
    if ($had_a) {
	print ALIASES "# alias = The Alias Name = the@address.of.them\n#\n";
	foreach $ali (sort (keys alias)) {
	    print ALIASES "$ali = $ali = $alias{$ali}\n";
	}
    }
    if ($had_g) {
	print ALIASES "#\n# group = The Group Name = person1[, person2, ..., person n]\n#\n";
	foreach $grp (sort (keys group)) {
	    print ALIASES "$grp = $grp = $group{$grp}\n";
	}
    }
    close(AT);
}

# chop down a set line
sub set_line {
    /[ \t]+(no)*askcc/ && do {
	print ELMRC "#\n# would you like to be asked for Carbon-Copies information each msg?\n";
	if ($1 eq "no") {
	    print ELMRC "askcc = OFF\n";
	} else {
	    print ELMRC "askcc = ON\n";
	}
    };
    
    /[ \t]+EDITOR=([^ \t]*)/ && do {
	if ($visual ne 1) {
	    print ELMRC "#\n# what editor to use\neditor = $1\n";
	    $editor = 1;
	}
    };
    
    /[ \t]+escape=([^ \t])/ && do {
	print ELMRC "#\n# the character to use in the builtin editor for";
	print ELRMC " entering commands\n# note that this was the";
	print ELMRC " `editor' variable in your .mailrc; its\n";
	print ELMRC "# functionality here isn't exactly the same\n";
	print ELMRC "escape = $1\n";
    };
    
    /[ \t]+folder=([^ \t]*)/ && do {
	print ELMRC "#\n# where to save my mail to, default directory is \"Mail\"\n";
	print ELMRC "maildir = $1\n";
    };
    
    /[ \t]+(no)*hold/ && do {
	print ELMRC "#\n# should the default be to store read messages to the \"received\" folder?\n";
	if ($1 eq "no") {
	    print ELMRC "alwaysstore = ON\n";
	} else {
	    print ELMRC "alwaysstore = OFF\n";
	}
	$hold = 1;
    };
    
    /[ \t]+(no)*keep[^s]/ && do {
	print ELMRC "#\n# should we keep folders from which all messages are deleted?\n";
	if ($1 eq "no") {
	    print ELMRC "keepempty = OFF\n";
	} else {
	    print ELMRC "keepempty = ON\n";
	}
    };
    
    /[ \t]+MBOX=([^ \t]*)/ && do {
	print ELMRC "#\n# where to save received messages to, default file is \"=received\"\n";
	$d = $1;
	# XXX: this may not always work properly
	if ($d =~ /\//) {
	    print ELMRC "receivedmail = $d\n";
	} else {
	    print ELMRC "recievedmail = =$d\n";
	}
    };
    
    /[ \t]+(no)*outfolder/ && do {
	print ELMRC "#\n# save a copy of all outbound messages?\n";
	if ($1 eq "no") {
	    print ELMRC "copy = OFF";
	} else {
	    print ELMRC "copy = ON";
	}
    };
    
    /[ \t]+PAGER=([^ \t]*)/ && do {
	print ELMRC "#\n# program to use for displaying messages\n";
	print ELMRC "pager = $1\n";
    };
    
    /[ \t]+record=([^ \t]*)/ && do {
	print ELMRC "#\n# where to save copies of outgoing mail to, default file is \"=sent\"\n";
	$d = $1;
	if ($d =~ /\//) {
	    print ELMRC "sentmail = $1\n";
	} else {
	    print ELMRC "sentmail = =$1\n";
	}
    };
    
    /[ \t]+SHELL=([^ \t]*)/ && do {
	print ELMRC "#\n# The shell to use for shell escapes\n";
	print ELMRC "shell = $1\n";
    };
    
    /[ \t]+VISUAL=([^ \t]*)/ && do {
	if ($editor ne 1) {
	    print ELMRC "#\n# what editor to use\neditor = $1\n";
	    $visual = 1;
	}
    };
}

-- cut --
-- 
     Brendan Kehoe - Widener Sun Network Manager - brendan@cs.widener.edu
  Widener University in Chester, PA                A Bloody Sun-Dec War Zone
  "Ya know, kitten tacos are really better than anything you've ever tasted
    before!"  "Oh, really."                              -- Rush Limbaugh