]> code.delx.au - offlineimap/blob - offlineimap/repository/Gmail.py
make the trash and spam folder names in Gmail accounts configurable
[offlineimap] / offlineimap / repository / Gmail.py
1 # Gmail IMAP repository support
2 # Copyright (C) 2008 Riccardo Murri <riccardo.murri@gmail.com>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18 from IMAP import IMAPRepository
19 from offlineimap import folder, imaputil
20 from offlineimap.imapserver import IMAPServer
21
22 class GmailRepository(IMAPRepository):
23 """Gmail IMAP repository.
24
25 Uses hard-coded host name and port, see:
26 http://mail.google.com/support/bin/answer.py?answer=78799&topic=12814
27 """
28
29 #: Gmail IMAP server hostname
30 HOSTNAME = "imap.gmail.com"
31
32 #: Gmail IMAP server port
33 PORT = 993
34
35 def __init__(self, reposname, account):
36 """Initialize a GmailRepository object."""
37 account.getconfig().set('Repository ' + reposname,
38 'remotehost', GmailRepository.HOSTNAME)
39 account.getconfig().set('Repository ' + reposname,
40 'remoteport', GmailRepository.PORT)
41 account.getconfig().set('Repository ' + reposname,
42 'ssl', 'yes')
43 IMAPRepository.__init__(self, reposname, account)
44
45 def gethost(self):
46 return GmailRepository.HOSTNAME
47
48 def getport(self):
49 return GmailRepository.PORT
50
51 def getssl(self):
52 return 1
53
54 def getpreauthtunnel(self):
55 return None
56
57 def getfolder(self, foldername):
58 return self.getfoldertype()(self.imapserver, foldername,
59 self.nametrans(foldername),
60 self.accountname, self)
61
62 def getfoldertype(self):
63 return folder.Gmail.GmailFolder
64
65 def getrealdelete(self, foldername):
66 # XXX: `foldername` is currently ignored - the `realdelete`
67 # setting is repository-wide
68 return self.getconfboolean('realdelete', 0)
69
70 def gettrashfolder(self, foldername):
71 #: Where deleted mail should be moved
72 return self.getconf('trashfolder','[Gmail]/Trash')
73
74 def getspamfolder(self):
75 #: Gmail also deletes messages upon EXPUNGE in the Spam folder
76 return self.getconf('spamfolder','[Gmail]/Spam')
77