Procházet zdrojové kódy

Merge pull request #133 from tilsammans/pop3s

Enabled POP3S for old-timeys who dig that
Luke Cyca před 11 roky
rodič
revize
f7cccbc89c

+ 1
- 0
README.textile Zobrazit soubor

@@ -28,6 +28,7 @@ h2. Services Provided
28 28
 What do you get if you point this thing at a VPS? All kinds of good stuff!
29 29
 
30 30
 * "IMAP":https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol over SSL via "Dovecot":http://dovecot.org/, complete with full text search provided by "Solr":https://lucene.apache.org/solr/.
31
+* "POP3":https://en.wikipedia.org/wiki/Post_Office_Protocol over SSL, also via Dovecot
31 32
 * "SMTP":https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol over SSL via Postfix, including a nice set of "DNSBLs":https://en.wikipedia.org/wiki/DNSBL to discard spam before it ever hits your filters.
32 33
 * Webmail via "Roundcube":http://www.roundcube.net/.
33 34
 * Mobile push notifications via "Z-Push":http://z-push.sourceforge.net/soswp/index.php?pages_id=1&t=home.

+ 1
- 0
roles/common/tasks/ufw.yml Zobrazit soubor

@@ -16,6 +16,7 @@
16 16
     - https/tcp
17 17
     - ssh/tcp
18 18
     - ssmtp/tcp
19
+    - pop3s/tcp
19 20
     - imaps/tcp
20 21
     - 5222/tcp  # xmpp c2s
21 22
     - 5269/tcp  # xmpp s2s

+ 1
- 1
roles/mailserver/files/etc_dovecot_dovecot.conf Zobrazit soubor

@@ -96,4 +96,4 @@ dict {
96 96
 # A config file can also tried to be included without giving an error if
97 97
 # it's not found:
98 98
 !include_try /usr/share/dovecot/protocols.d/*.protocol
99
-protocols = imap lmtp sieve
99
+protocols = imap lmtp sieve pop3

+ 1
- 0
roles/mailserver/tasks/dovecot.yml Zobrazit soubor

@@ -3,6 +3,7 @@
3 3
   with_items:
4 4
     - dovecot-core
5 5
     - dovecot-imapd
6
+    - dovecot-pop3d
6 7
     - dovecot-lmtpd
7 8
     - dovecot-managesieved
8 9
     - postgresql-9.1

+ 2
- 1
roles/monitoring/files/etc_monit_conf.d_dovecot Zobrazit soubor

@@ -3,4 +3,5 @@ check process dovecot with pidfile /var/run/dovecot/master.pid
3 3
   start program = "/etc/init.d/dovecot start"
4 4
   stop program = "/etc/init.d/dovecot stop"
5 5
   if failed port 993 type tcpssl sslauto protocol imap for 5 cycles then restart
6
-  if 3 restarts within 5 cycles then timeout
6
+  if failed port 995 type tcpssl sslauto protocol pop for 5 cycles then restart
7
+  if 3 restarts within 5 cycles then timeout

+ 44
- 7
tests.py Zobrazit soubor

@@ -161,8 +161,8 @@ def new_message(from_email, to_email):
161 161
 
162 162
 
163 163
 class MailTests(unittest.TestCase):
164
-    def assertEmailReceived(self, subject):
165
-        """Connects with IMAP and asserts the existance of an email, then deletes it"""
164
+    def assertIMAPReceived(self, subject):
165
+        """Connects with IMAP and asserts the existence of an email, then deletes it"""
166 166
         import imaplib
167 167
 
168 168
         sleep(1)
@@ -172,7 +172,7 @@ class MailTests(unittest.TestCase):
172 172
         m.login(TEST_ADDRESS, TEST_PASSWORD)
173 173
         m.select()
174 174
 
175
-        # Assert the message exist
175
+        # Assert the message exists
176 176
         typ, data = m.search(None, '(SUBJECT \"{}\")'.format(subject))
177 177
         self.assertTrue(len(data[0].split()), 1)
178 178
 
@@ -182,6 +182,26 @@ class MailTests(unittest.TestCase):
182 182
         m.close()
183 183
         m.logout()
184 184
 
185
+    def assertPOP3Received(self, subject):
186
+        """Connects with POP3S and asserts the existence of an email, then deletes it"""
187
+        import poplib
188
+
189
+        sleep(1)
190
+
191
+        # Login to POP3
192
+        mail = poplib.POP3_SSL(TEST_SERVER, 995)
193
+        mail.user(TEST_ADDRESS)
194
+        mail.pass_(TEST_PASSWORD)
195
+
196
+        # Assert the message exists
197
+        num = len(mail.list()[1])
198
+        resp, text, octets = mail.retr(num)
199
+        self.assertTrue("Subject: " + subject in text)
200
+
201
+        # Delete it and log out
202
+        mail.dele(num)
203
+        mail.quit()
204
+
185 205
     def test_imap_requires_ssl(self):
186 206
         """IMAP without SSL is NOT available"""
187 207
         import imaplib
@@ -189,6 +209,13 @@ class MailTests(unittest.TestCase):
189 209
         with self.assertRaisesRegexp(socket.timeout, 'timed out'):
190 210
             imaplib.IMAP4(TEST_SERVER, 143)
191 211
 
212
+    def test_pop3_requires_ssl(self):
213
+        """POP3 without SSL is NOT available"""
214
+        import poplib
215
+
216
+        with self.assertRaisesRegexp(socket.timeout, 'timed out'):
217
+            poplib.POP3(TEST_SERVER, 110)
218
+
192 219
     def test_smtps(self):
193 220
         """Email sent from an MUA via SMTPS is delivered"""
194 221
         import smtplib
@@ -197,7 +224,7 @@ class MailTests(unittest.TestCase):
197 224
         s.login(TEST_ADDRESS, TEST_PASSWORD)
198 225
         s.sendmail(TEST_ADDRESS, ['root@sovereign.local'], msg)
199 226
         s.quit()
200
-        self.assertEmailReceived(subject)
227
+        self.assertIMAPReceived(subject)
201 228
 
202 229
     def test_smtps_delimiter_to(self):
203 230
         """Email sent to address with delimiter is delivered"""
@@ -207,7 +234,7 @@ class MailTests(unittest.TestCase):
207 234
         s.login(TEST_ADDRESS, TEST_PASSWORD)
208 235
         s.sendmail(TEST_ADDRESS, ['root+foo@sovereign.local'], msg)
209 236
         s.quit()
210
-        self.assertEmailReceived(subject)
237
+        self.assertIMAPReceived(subject)
211 238
 
212 239
     def test_smtps_requires_auth(self):
213 240
         """SMTPS with no authentication is rejected"""
@@ -226,7 +253,7 @@ class MailTests(unittest.TestCase):
226 253
         s = smtplib.SMTP(TEST_SERVER, 25)
227 254
         s.sendmail('someone@example.com', [TEST_ADDRESS], msg)
228 255
         s.quit()
229
-        self.assertEmailReceived(subject)
256
+        self.assertIMAPReceived(subject)
230 257
 
231 258
     def test_smtp_tls(self):
232 259
         """Email sent from an MTA via SMTP+TLS is delivered"""
@@ -236,7 +263,7 @@ class MailTests(unittest.TestCase):
236 263
         s.starttls()
237 264
         s.sendmail('someone@example.com', [TEST_ADDRESS], msg)
238 265
         s.quit()
239
-        self.assertEmailReceived(subject)
266
+        self.assertIMAPReceived(subject)
240 267
 
241 268
     def test_smtps_headers(self):
242 269
         """Email sent from an MUA has DKIM and TLS headers"""
@@ -312,6 +339,16 @@ class MailTests(unittest.TestCase):
312 339
         m.close()
313 340
         m.logout()
314 341
 
342
+    def test_pop3s(self):
343
+        """Connects with POP3S and asserts the existance of an email, then deletes it"""
344
+        import smtplib
345
+        msg, subject = new_message(TEST_ADDRESS, 'root@sovereign.local')
346
+        s = smtplib.SMTP_SSL(TEST_SERVER, 465)
347
+        s.login(TEST_ADDRESS, TEST_PASSWORD)
348
+        s.sendmail(TEST_ADDRESS, ['root@sovereign.local'], msg)
349
+        s.quit()
350
+        self.assertPOP3Received(subject)
351
+
315 352
 
316 353
 class XMPPTests(unittest.TestCase):
317 354
     def test_xmpp_c2s(self):

Loading…
Zrušit
Uložit