File: licq2mutt

package info (click to toggle)
licq 1.3.4-2
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 22,048 kB
  • ctags: 8,640
  • sloc: cpp: 76,924; sh: 9,845; ansic: 5,424; perl: 3,449; lex: 857; xml: 804; php: 691; makefile: 393; csh: 48
file content (117 lines) | stat: -rwxr-xr-x 3,117 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/perl -w
#
# Licq2Mutt Version 1.0.1.
# Public Domain by Javier Kohen <jkohen@tough.com>, 2000.
#
# Builds a text file containing e-mail addresses in Mutt format for a given set of Licq 1.0 compatible users files.
#
# Suggested use:
#  * The first time you run this program, run the following command to have the aliases file sourced into your Mutt configuration:
#  echo source ~/.muttrc-alias-licq >> ~/.muttrc
#
#  * Then, everytime you change your users list, run this command:
#  licq2mutt > ~/.muttrc-alias-licq
#  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.
#
# BUGS:
#  * If two users have the same nick, Mutt will ignore one of them.
#    The only fix I've imagined for this is appending the UIN to the nick, but IMO that isn't user friendly.
#
# HISTORY:
#  * 1.0.1 - Added escaped quote marks around user's name to improve Mutt's parser behavior.
#  * 1.0.0 - First Release
#

use strict;

use Getopt::Std;

my $VERSION = "Licq2Mutt version 1.0.1.\
Public Domain by Javier Kohen <jkohen\@tough.com>, 2000\n";

sub print_version() {
    print STDERR $VERSION;
}

sub print_help() {
    print STDERR
"Usage: $0 [options]\
Options:\
 -h\t\tShow this help.\
 -v\t\tShow program version info.\
 -q\t\tBe quiet.\
 -p <prefix>\tPrepend PREFIX to every alias. Defaults to nothing.\
 -b <base>\tUse BASE directory to find users files. Defaults to \$HOME/.licq.\n";
}

my %opts;

getopts('hvqp:b:', \%opts);

if ($opts{'v'}) {
    print_version();
    exit 0;
}

if ($opts{'h'}) {
    print_version();
    print_help();
    exit 0;
}

my $quiet = $opts{'q'} || 0;
my $base_directory = $opts{'b'} || "$ENV{'HOME'}/.licq";
my $space_translation = $opts{'s'} || '_';

print_version() unless $quiet;

@ARGV = glob("${base_directory}/users/*.uin");

die "Can't find users/*.uin in $base_directory.\n" if (-1 == $#ARGV);

print STDERR "Loading data...\n" unless $quiet;

my %alias;

while (<>) {
    my $uin = $ARGV;
    $uin =~ s/.*\/(\d+).uin/$1/;

    $alias{$uin}->{'nick'} = $1 if /^Alias = (.+)/;
    $alias{$uin}->{'fname'} = $1 if /^FirstName = (.+)/;
    $alias{$uin}->{'lname'} = $1 if /^LastName = (.+)/;
    $alias{$uin}->{'email1'} = $1 if /^Email1 = (.+)/;
    $alias{$uin}->{'email2'} = $1 if /^Email2 = (.+)/;
}

print STDERR "Generating aliases...\n" unless $quiet;

print "# Generated by " . join("\n# ", split("\n", $VERSION)) . "\n";
print "# Base Directory = $base_directory\n";

my $uin;

foreach $uin (keys %alias) {
    my $user = $alias{$uin};

    my $nick = $user->{'nick'};
    # Prepend PREFIX string, if specified.
    if ($opts{'p'}) {
	$nick = $opts{'p'} . $nick;
    }
    # Avoid using space characters in nick names.
    $nick =~ tr/ /_/;

    my $fname = $user->{'fname'} || '';
    my $lname = $user->{'lname'} || '';

    if (defined $user->{'email1'}) {
	print "alias $nick \\\"$fname $lname\\\" <$user->{'email1'}>\n";
	$nick .= '-2';
    }
    if (defined $user->{'email2'}) {
	print "alias $nick \\\"$fname $lname\\\" <$user->{'email2'}>\n";
    }
}

print STDERR "Done!\n" unless $quiet;