| 1 | #!/usr/bin/perl -w |
|---|
| 2 | # |
|---|
| 3 | # Licq2Mutt Version 1.0.1. |
|---|
| 4 | # Public Domain by Javier Kohen <jkohen@tough.com>, 2000. |
|---|
| 5 | # |
|---|
| 6 | # Builds a text file containing e-mail addresses in Mutt format for a given set of Licq 1.0 compatible users files. |
|---|
| 7 | # |
|---|
| 8 | # Suggested use: |
|---|
| 9 | # * The first time you run this program, run the following command to have the aliases file sourced into your Mutt configuration: |
|---|
| 10 | # echo source ~/.muttrc-alias-licq >> ~/.muttrc |
|---|
| 11 | # |
|---|
| 12 | # * Then, everytime you change your users list, run this command: |
|---|
| 13 | # licq2mutt > ~/.muttrc-alias-licq |
|---|
| 14 | # Probably putting that line in a cron job will be more useful, in that case you will want to append the -q (be quiet) switch. |
|---|
| 15 | # |
|---|
| 16 | # BUGS: |
|---|
| 17 | # * If two users have the same nick, Mutt will ignore one of them. |
|---|
| 18 | # The only fix I've imagined for this is appending the UIN to the nick, but IMO that isn't user friendly. |
|---|
| 19 | # |
|---|
| 20 | # HISTORY: |
|---|
| 21 | # * 1.0.1 - Added escaped quote marks around user's name to improve Mutt's parser behavior. |
|---|
| 22 | # * 1.0.0 - First Release |
|---|
| 23 | # |
|---|
| 24 | |
|---|
| 25 | use strict; |
|---|
| 26 | |
|---|
| 27 | use Getopt::Std; |
|---|
| 28 | |
|---|
| 29 | my $VERSION = "Licq2Mutt version 1.0.1.\ |
|---|
| 30 | Public Domain by Javier Kohen <jkohen\@tough.com>, 2000\n"; |
|---|
| 31 | |
|---|
| 32 | sub print_version() { |
|---|
| 33 | print STDERR $VERSION; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | sub print_help() { |
|---|
| 37 | print STDERR |
|---|
| 38 | "Usage: $0 [options]\ |
|---|
| 39 | Options:\ |
|---|
| 40 | -h\t\tShow this help.\ |
|---|
| 41 | -v\t\tShow program version info.\ |
|---|
| 42 | -q\t\tBe quiet.\ |
|---|
| 43 | -p <prefix>\tPrepend PREFIX to every alias. Defaults to nothing.\ |
|---|
| 44 | -b <base>\tUse BASE directory to find users files. Defaults to \$HOME/.licq.\n"; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | my %opts; |
|---|
| 48 | |
|---|
| 49 | getopts('hvqp:b:', \%opts); |
|---|
| 50 | |
|---|
| 51 | if ($opts{'v'}) { |
|---|
| 52 | print_version(); |
|---|
| 53 | exit 0; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | if ($opts{'h'}) { |
|---|
| 57 | print_version(); |
|---|
| 58 | print_help(); |
|---|
| 59 | exit 0; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | my $quiet = $opts{'q'} || 0; |
|---|
| 63 | my $base_directory = $opts{'b'} || "$ENV{'HOME'}/.licq"; |
|---|
| 64 | my $space_translation = $opts{'s'} || '_'; |
|---|
| 65 | |
|---|
| 66 | print_version() unless $quiet; |
|---|
| 67 | |
|---|
| 68 | @ARGV = glob("${base_directory}/users/*.uin"); |
|---|
| 69 | |
|---|
| 70 | die "Can't find users/*.uin in $base_directory.\n" if (-1 == $#ARGV); |
|---|
| 71 | |
|---|
| 72 | print STDERR "Loading data...\n" unless $quiet; |
|---|
| 73 | |
|---|
| 74 | my %alias; |
|---|
| 75 | |
|---|
| 76 | while (<>) { |
|---|
| 77 | my $uin = $ARGV; |
|---|
| 78 | $uin =~ s/.*\/(\d+).uin/$1/; |
|---|
| 79 | |
|---|
| 80 | $alias{$uin}->{'nick'} = $1 if /^Alias = (.+)/; |
|---|
| 81 | $alias{$uin}->{'fname'} = $1 if /^FirstName = (.+)/; |
|---|
| 82 | $alias{$uin}->{'lname'} = $1 if /^LastName = (.+)/; |
|---|
| 83 | $alias{$uin}->{'email1'} = $1 if /^Email1 = (.+)/; |
|---|
| 84 | $alias{$uin}->{'email2'} = $1 if /^Email2 = (.+)/; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | print STDERR "Generating aliases...\n" unless $quiet; |
|---|
| 88 | |
|---|
| 89 | print "# Generated by " . join("\n# ", split("\n", $VERSION)) . "\n"; |
|---|
| 90 | print "# Base Directory = $base_directory\n"; |
|---|
| 91 | |
|---|
| 92 | my $uin; |
|---|
| 93 | |
|---|
| 94 | foreach $uin (keys %alias) { |
|---|
| 95 | my $user = $alias{$uin}; |
|---|
| 96 | |
|---|
| 97 | my $nick = $user->{'nick'}; |
|---|
| 98 | # Prepend PREFIX string, if specified. |
|---|
| 99 | if ($opts{'p'}) { |
|---|
| 100 | $nick = $opts{'p'} . $nick; |
|---|
| 101 | } |
|---|
| 102 | # Avoid using space characters in nick names. |
|---|
| 103 | $nick =~ tr/ /_/; |
|---|
| 104 | |
|---|
| 105 | my $fname = $user->{'fname'} || ''; |
|---|
| 106 | my $lname = $user->{'lname'} || ''; |
|---|
| 107 | |
|---|
| 108 | if (defined $user->{'email1'}) { |
|---|
| 109 | print "alias $nick \\\"$fname $lname\\\" <$user->{'email1'}>\n"; |
|---|
| 110 | $nick .= '-2'; |
|---|
| 111 | } |
|---|
| 112 | if (defined $user->{'email2'}) { |
|---|
| 113 | print "alias $nick \\\"$fname $lname\\\" <$user->{'email2'}>\n"; |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | print STDERR "Done!\n" unless $quiet; |
|---|