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
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2010 Kolab Systems AG (http://www.kolabsys.com)
#
# Paul James Adams <adams a kolabsys.com>
# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 only
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
import os, random, sys
if __name__ == "__main__":
wanted_num = int(sys.argv[1])
contact_tpl_file = open('./kaddress-contact.tpl', 'r')
contact_tpl_orig = contact_tpl_file.read()
contact_tpl_file.close()
users = ['john', 'joe', 'max']
domains = ['doe.org', 'sixpack.com', 'imum.net']
uid_alloc = []
alphabet = "abcdefghijklmnopqrstuvwxwz"
user_num = 0
for user in users:
num = 0
while num <= wanted_num:
uid = "%s.%s" %(str(random.randint(1000000000,9999999999)),str(random.randint(0,999)).zfill(3))
if not uid in uid_alloc:
uid_alloc.append(uid)
else:
continue
domain = domains[random.randint(0,2)]
contact_tpl = contact_tpl_orig
birthday = ""
if random.randint(0,100) >= 75:
year = str(random.randint(1960, 2010))
month = str(random.randint(1,12)).zfill(2)
day = str(random.randint(1,27)).zfill(2)
birthday = "%s-%s-%s" % (year, month, day)
middle_names = ""
if random.randint(0,100) >= 50:
middle_names = ''.join(random.sample(alphabet, random.randint(4, 8))).capitalize()
number = ""
if random.randint(0,100) >= 25:
number = "+441234567890"
given_name = ''.join(random.sample(alphabet, random.randint(4, 8))).capitalize()
last_name = ''.join(random.sample(alphabet, random.randint(4, 8))).capitalize()
contact = {
'uid': uid,
'user': user,
'user_email': "%s@%s" % (user, domain),
'given_name': given_name,
'middle_names': middle_names,
'last_name': last_name,
'full_name': "%s %s %s" % (given_name, middle_names, last_name),
'display_name': "%s %s" % (given_name, last_name),
'email_address': "%s@%s" % (given_name, domain),
'number': number,
'birthday': birthday
}
directory = "/kolab/var/imapd/spool/domain/%s/%s/%s/user/%s/Contacts" %(domains[user_num][0],domains[user_num],user[0],user)
if not os.path.isdir(directory):
directory = "./kolab/var/imapd/spool/domain/%s/%s/%s/user/%s/Contacts" %(domains[user_num][0],domains[user_num],user[0],user)
if not os.path.isdir(directory):
os.makedirs(directory)
out = open("%s/%d." %(directory,num), 'w')
for key in contact.keys():
contact_tpl = contact_tpl.replace("@@%s@@" % key, '%s' % contact[key])
out.write(contact_tpl)
out.close()
try:
os.chown("%s/%d." %(directory,num), 19415, 19415)
except:
pass
num += 1
user_num += 1
|