3 szs/biff - an imap/pop biff module for SZS a statusbar script for WMI
9 * changed config format
10 * added multiple server support
12 * added seperate multipliers for pop and imap
13 * added support for POP3 SSL (python 2.4 only)
14 * added support for IMAP4 SSL
17 * show <mailbox>(?) on startup and if serer is not reachable
20 * implemented error handling
33 Copyright 2004 Christoph Wegscheider <cw@wegi.net>
38 This program is free software; you can redistribute it and/or modify
39 it under the terms of the GNU General Public License as published by
40 the Free Software Foundation; either version 2 of the License, or
41 (at your option) any later version.
43 This program is distributed in the hope that it will be useful,
44 but WITHOUT ANY WARRANTY; without even the implied warranty of
45 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46 GNU General Public License for more details.
48 You should have received a copy of the GNU General Public License
49 along with this program; if not, write to the Free Software
50 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
65 if type(mailboxes) is not types.ListType:
66 mailboxes = [['', mailboxes]]
68 text += it[1] + '(?) '
79 if count % multiplier['imapmultiplier'] == 1:
81 for acc in accounts['imapaccount']:
84 server = imaplib.IMAP4_SSL(acc[0])
86 server = imaplib.IMAP4(acc[0])
87 server.login(acc[1], acc[2])
89 if server.select(it[0], True)[0] == 'OK':
90 num = len(server.search(None, 'UNSEEN')[1][0].split())
92 imaptext += it[1] + '(' + str(num) + ') '
94 except (imaplib.IMAP4.error, socket.error), errormsg:
95 msg.debug(acc[0] + ": " + str(errormsg), 2)
96 imaptext += error(acc[4:])
99 if count % multiplier['popmultiplier'] == 1:
101 for acc in accounts['popaccount']:
104 if sys.version_info >= (2,4):
105 server = poplib.POP3_SSL(acc[0])
107 raise szstoolbox.Error('POP3 with SSL support is only availabe in python 2.4 or greater')
109 server = poplib.POP3(acc[0])
112 num = server.stat()[0]
115 poptext += acc[4] + '(' + str(num) + ') '
116 except (poplib.error_proto, socket.error, szstoolbox.Error), e:
117 msg.debug(acc[0] + ': ' + str(e), 2)
118 poptext += error(acc[4])
121 return [imaptext + poptext]
127 imaptext = poptext = ''
128 accounts = multiplier = {}
129 msg = szstoolbox.MSG()
130 cfg = szstoolbox.CFG('biff')
133 for it in 'imapmultiplier','popmultiplier':
134 multiplier[it] = int(cfg.read(it))
135 for acctype in 'imapaccount','popaccount':
136 accounts[acctype] = []
137 config = cfg.read(acctype)
138 if type(config) is types.StringType:
140 elif type(config) is types.NoneType:
144 accounts[acctype].append(acc[0].split(':'))
145 if acctype == 'imapaccount':
146 accounts[acctype][-1].extend([it.split(':') for it in acc[1:]])
148 # set nice start text
149 for acc in accounts['imapaccount']:
150 imaptext += error(acc[3:])
151 for acc in accounts['popaccount']:
152 poptext += error(acc[4])
156 # for testing purpose
157 if __name__ == '__main__':
162 time.sleep(szstoolbox.interval)