.

Add Long Names to a Mutt Alias File
2008-06-10 15:49 -0400

It is always fun writing scripts to solve problems. Here, I have a pretty extensive mutt alias file, consisting of records such as:

alias john_doe      john.doe@example.com
alias kate          kate_doe@example.com

The name is either the first name or first_last followed by the email address. I wanted to add a long name so that when I composed an email the To: header would read:

To: <long name> <email address>

This is certainly not a big deal, but I wrote a simple perl script to achieve this. It generates the long name from the alias by replacing underscores with spaces. The long name is appended to each line in parenthesis. It takes the alias file on the command line and writes to stdout. It is specialized for my circumstances but may be of use to others.

#!/usr/bin/perl
use strict;
use warnings;

#----------------------------------------------
# Usage add_names <alias file>
#   Appends the person's name to the end
#   of the line of a mutt mail alias file.
#   The name appended is based on the alias.
#   Writes results to stdout.
#----------------------------------------------

while (my $line = <>) {
    chomp $line;
    my @fields = split /\s+/, $line;
    my $name = $fields[1];
    $name =~ s/_/ /g;
    my $result = sprintf '%-5s %-20s %-35s (%s)', $fields[0], $fields[1], 
        $fields[2], $name;
    print "$result\n";
}

When run on the sample alias file above, it gives the following output:

alias john_doe             john.doe@example.com                (john doe)
alias kate                 kate_doe@example.com                (kate)

Again, this is not a task of any great importance; it is just an example where a simple script allowed me to complete a task that I wouldn't have been willing to do manually.