Complete.Org: Mailing Lists: Archives: offlineimap: October 2005:
Re: Multiple Accounts
Home

Re: Multiple Accounts

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: offlineimap@xxxxxxxxxxxx
Subject: Re: Multiple Accounts
From: Sweth Chandramouli <offlineimap@xxxxxxxxxxxxxxx>
Date: Thu, 20 Oct 2005 01:19:01 -0400

On Thursday, 20 October 2005 at 00:37:58 EDT,
   Jon Riddle (<list@xxxxxxxxxxxxxxxxx>) wrote:
> But I don't want to set the defaults for everything.  I want to define a
> remote repository and a local repository (both IMAP servers in my case)
> and have one account section per user, with usernames and passwords in
> each section.

Actually, what you really seem to want is to not have to deal with the
repetitive task of entering the same info for each account and repository
multiple times; the easiest solution to that problem isn't adding bloat
to offlineimap, but instead just scripting the generation of your
offlineimaprc:

#!/usr/bin/perl -w

use strict;
my ($localhost, $remotehost) = ('host1', 'host2');

my %passwd_from_user = map { chomp; split (/,/ => $_) } <ARGV>;
print "[general]\n";
print "accounts = " . join (',' => sort keys %passwd_from_user) . "\n\n";
for my $userid (sort keys %passwd_from_user) {
        print <<"EOF"
[Account $userid]
localrepository = ${localhost}_$userid
remoterepository = ${remotehost}_$userid

[Repository ${localhost}_$userid]
type = IMAP
remotehost = $localhost
remoteuser = $userid
remotepass = $passwd_from_user{$userid}

[Repository ${remotehost}_$userid]
type = IMAP
remotehost = $remotehost
remoteuser = $userid
remotepass = $passwd_from_user{$userid}

EOF
};
__END__

will take as input a file like:

user1,pass1
user2,pass2
user3,pass3

and generate as output:

[general]
accounts = user1,user2,user3

[Account user1]
localrepository = host1_user1
remoterepository = host2_user1

[Repository host1_user1]
type = IMAP
remotehost = host1
remoteuser = user1
remotepass = pass1

[Repository host2_user1]
type = IMAP
remotehost = host2
remoteuser = user1
remotepass = pass1

[Account user2]
localrepository = host1_user2
remoterepository = host2_user2

[Repository host1_user2]
type = IMAP
remotehost = host1
remoteuser = user2
remotepass = pass2

[Repository host2_user2]
type = IMAP
remotehost = host2
remoteuser = user2
remotepass = pass2

[Account user3]
localrepository = host1_user3
remoterepository = host2_user3

[Repository host1_user3]
type = IMAP
remotehost = host1
remoteuser = user3
remotepass = pass3

[Repository host2_user3]
type = IMAP
remotehost = host2
remoteuser = user3
remotepass = pass3

-- Sweth.  (Yes, it's perl, not python.  It still gets the job done.)

-- 
Sweth Chandramouli
sweth@xxxxxxxxxxxxxxxx - http://EthicalHomes.com/
Thinking about buying a home, but feel like the local DC real estate market
has left you behind?  Know others who have the same questions?  I teach at
homebuying seminars for local housing agencies, and would be glad to help
set up a free seminar for your company or organization.



[Prev in Thread] Current Thread [Next in Thread]