2 # -*- coding: utf-8 -*-
4 #Copyright 2010-2011 Steffen Schaumburg
5 #This program is free software: you can redistribute it and/or modify
6 #it under the terms of the GNU Affero General Public License as published by
7 #the Free Software Foundation, version 3 of the License.
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.
14 #You should have received a copy of the GNU Affero General Public License
15 #along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #In the "official" distribution you can find the license in agpl-3.0.txt.
19 _
= L10n
.get_translation()
25 from imaplib
import IMAP4
26 from socket
import gaierror
30 class GuiImapFetcher (threading
.Thread
):
31 def __init__(self
, config
, db
, sql
, mainwin
, debug
=True):
34 self
.mainVBox
= gtk
.VBox()
37 self
.buttonsHBox
= gtk
.HBox()
38 self
.mainVBox
.pack_end(self
.buttonsHBox
, expand
=False)
40 label
=gtk
.Label(_("To cancel just close this tab."))
41 self
.buttonsHBox
.add(label
)
43 self
.saveButton
= gtk
.Button(_("_Save"))
44 self
.saveButton
.connect('clicked', self
.saveClicked
)
45 self
.buttonsHBox
.add(self
.saveButton
)
47 self
.importAllButton
= gtk
.Button(_("_Import All"))
48 self
.importAllButton
.connect('clicked', self
.importAllClicked
)
49 self
.buttonsHBox
.add(self
.importAllButton
)
51 self
.statusLabel
=gtk
.Label(_("If you change the config you must save before importing"))
52 self
.mainVBox
.pack_end(self
.statusLabel
, expand
=False, padding
=4)
57 self
.mainVBox
.show_all()
60 def saveClicked(self
, widget
, data
=None):
61 row
= self
.rowVBox
.get_children()
62 columns
=row
[0].get_children() #TODO: make save capable of handling multiple email entries - not relevant yet as only one entry is useful atm. The rest of this tab works fine for multiple entries though
64 siteName
=columns
[0].get_text()
65 fetchType
=columns
[1].get_text()
67 toSave
=self
.config
.supported_sites
[siteName
].emails
[fetchType
]
69 toSave
.host
=columns
[2].get_text()
70 toSave
.username
=columns
[3].get_text()
72 if columns
[4].get_text()=="***":
73 toSave
.password
=self
.passwords
[siteName
+fetchType
]
75 toSave
.password
=columns
[4].get_text()
77 toSave
.folder
=columns
[5].get_text()
79 if columns
[6].get_active() == 0:
84 self
.config
.editEmail(siteName
, fetchType
, toSave
)
88 def importAllClicked(self
, widget
, data
=None):
89 self
.statusLabel
.set_label(_("Starting import. Please wait.")) #FIXME: why doesnt this one show?
90 for siteName
in self
.config
.supported_sites
:
91 for fetchType
in self
.config
.supported_sites
[siteName
].emails
:
93 result
=ImapFetcher
.run(self
.config
.supported_sites
[siteName
].emails
[fetchType
], self
.db
)
94 self
.statusLabel
.set_label(_("Finished import without error."))
95 except IMAP4
.error
as error
:
96 if str(error
)=="[AUTHENTICATIONFAILED] Authentication failed.":
97 self
.statusLabel
.set_label(_("Login to mailserver failed: please check mailserver, username and password"))
98 except gaierror
as error
:
99 if str(error
)=="[Errno -2] Name or service not known":
100 self
.statusLabel
.set_label(_("Could not connect to mailserver: check mailserver and use SSL settings and internet connectivity"))
101 #def importAllClicked
104 """returns the vbox of this thread"""
108 def displayConfig(self
):
109 box
=gtk
.HBox(homogeneous
=True)
110 for text
in (_("Site"), _("Fetch Type"), _("Mail Server"), _("Username"), _("Password"), _("Mail Folder"), _("Use SSL")):
111 label
=gtk
.Label(text
)
113 self
.mainVBox
.pack_start(box
, expand
=False)
115 self
.rowVBox
= gtk
.VBox()
116 self
.mainVBox
.add(self
.rowVBox
)
118 for siteName
in self
.config
.supported_sites
:
119 for fetchType
in self
.config
.supported_sites
[siteName
].emails
:
120 config
=self
.config
.supported_sites
[siteName
].emails
[fetchType
]
121 box
=gtk
.HBox(homogeneous
=True)
123 for field
in (siteName
, config
.fetchType
):
124 label
=gtk
.Label(field
)
127 for field
in (config
.host
, config
.username
):
129 entry
.set_text(field
)
133 self
.passwords
[siteName
+fetchType
]=config
.password
134 entry
.set_text("***")
138 entry
.set_text(config
.folder
)
141 sslBox
= gtk
.combo_box_new_text()
142 sslBox
.append_text(_("Yes"))
143 sslBox
.append_text(_("No"))
150 #TODO: "run just this one" button
152 self
.rowVBox
.pack_start(box
, expand
=False)
155 self
.mainVBox
.show_all()
156 #end def displayConfig
157 #end class GuiImapFetcher