root/trunk/licq/bin/licq2mutt

Revision 4526, 3.0 kB (checked in by erijo, 2 years ago)

Removed svn:keywords from all files that don't need it. May make your
checkout a tiny bit faster :)

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
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
25use strict;
26
27use Getopt::Std;
28
29my $VERSION = "Licq2Mutt version 1.0.1.\
30Public Domain by Javier Kohen <jkohen\@tough.com>, 2000\n";
31
32sub print_version() {
33    print STDERR $VERSION;
34}
35
36sub print_help() {
37    print STDERR
38"Usage: $0 [options]\
39Options:\
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
47my %opts;
48
49getopts('hvqp:b:', \%opts);
50
51if ($opts{'v'}) {
52    print_version();
53    exit 0;
54}
55
56if ($opts{'h'}) {
57    print_version();
58    print_help();
59    exit 0;
60}
61
62my $quiet = $opts{'q'} || 0;
63my $base_directory = $opts{'b'} || "$ENV{'HOME'}/.licq";
64my $space_translation = $opts{'s'} || '_';
65
66print_version() unless $quiet;
67
68@ARGV = glob("${base_directory}/users/*.uin");
69
70die "Can't find users/*.uin in $base_directory.\n" if (-1 == $#ARGV);
71
72print STDERR "Loading data...\n" unless $quiet;
73
74my %alias;
75
76while (<>) {
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
87print STDERR "Generating aliases...\n" unless $quiet;
88
89print "# Generated by " . join("\n# ", split("\n", $VERSION)) . "\n";
90print "# Base Directory = $base_directory\n";
91
92my $uin;
93
94foreach $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
117print STDERR "Done!\n" unless $quiet;
Note: See TracBrowser for help on using the browser.