From 0b4d804f115f5f86cb49f6e312f4a42ba4f13f83 Mon Sep 17 00:00:00 2001
From: Romeo Papa <romeopapa@caramail.com>
Date: Wed, 12 Aug 2015 06:06:47 +0200
Subject: [PATCH 2/3] The SOCKS host and port can be configured in
 whisperback's config.py

---
 debian/control             |  4 ++--
 doc/config.py.sample       |  9 +++++++++
 whisperBack/mail.py        | 11 +++++++----
 whisperBack/whisperback.py |  9 ++++++++-
 4 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/debian/control b/debian/control
index 877d6ad..f0ccf21 100644
--- a/debian/control
+++ b/debian/control
@@ -12,8 +12,8 @@ X-Python3-Version: >= 3.4
 
 Package: whisperback
 Architecture: all
-Depends: ${misc:Depends}, ${python3:Depends}, python3-gnupg, python3-gi,
- python3-pysocks, gir1.2-gtk-3.0, gir1.2-webkit-3.0, gir1.2-glib-2.0
+Depends: ${misc:Depends}, ${python3:Depends}, python3-regex, python3-gnupg,
+ python3-gi, python3-pysocks, gir1.2-gtk-3.0, gir1.2-webkit-3.0, gir1.2-glib-2.0
 Description: send feedback using encrypted email
  WhisperBack is designed to allow Live system users to be able to report bugs
  or issues in a simple yet secure manner.
diff --git a/doc/config.py.sample b/doc/config.py.sample
index 0c19abf..f273ea8 100644
--- a/doc/config.py.sample
+++ b/doc/config.py.sample
@@ -83,6 +83,15 @@ smtp_port = 25
 # certificate or the certificate of the SMTP server itself
 smtp_tlscafile = os.path.join("path", "to", "ca")
 
+# SOCKS
+#
+# This section defines the SOCKS proxy parameters
+#
+# The SOCKS proxy to use to send the mail
+socks_host = "127.0.0.1"
+# The port to connect to on that SOCKS proxy
+socks_port = 9500
+
 # MESSAGE
 #
 # This section defines the message parameters
diff --git a/whisperBack/mail.py b/whisperBack/mail.py
index 139b988..fa5d9e0 100644
--- a/whisperBack/mail.py
+++ b/whisperBack/mail.py
@@ -26,14 +26,15 @@
 """
 
 import smtplib
-import ssl
-import time
 import socket
 import socks
+import ssl
+import time
 
 #pylint: disable=R0913
 def send_message_tls (from_address, to_address, message, host="localhost",
-                      port=25, tls_cafile=None):
+                      port=25, tls_cafile=None, socks_host="127.0.0.1",
+                      socks_port=9050):
     """Sends a mail
 
     Send the message via our own SMTP server, but don't include the
@@ -45,10 +46,12 @@ def send_message_tls (from_address, to_address, message, host="localhost",
     @param host The host of the smtp server to connect to
     @param port The port of the smtp server to connect to
     @param tls_cafile Certificate authority file used to create the SSLContext
+    @param socks_host The host of the SOCKS proxy to connect through
+    @param socks_port The port of the SOCKS proxy to connect through
     """
 
     # Monkeypatching the entire connection through the SOCKS proxy
-    socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 9050)
+    socks.set_default_proxy(socks.SOCKS5, socks_host, socks_port)
     socket.socket = socks.socksocket
 
     ssl_context = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH,
diff --git a/whisperBack/whisperback.py b/whisperBack/whisperback.py
index 5f41dd9..d94adb1 100644
--- a/whisperBack/whisperback.py
+++ b/whisperBack/whisperback.py
@@ -100,6 +100,8 @@ class WhisperBack(object):
         self.smtp_host = None
         self.smtp_port = None
         self.smtp_tlscafile = None
+        self.socks_host = None
+        self.socks_port = None
 
         # Load the python configuration file "config.py" from diffrents locations
         # XXX: this is an absolute path, bad !
@@ -163,6 +165,10 @@ class WhisperBack(object):
             raise whisperBack.exceptions.MisconfigurationException('smtp_port')
         if not self.smtp_tlscafile:
             raise whisperBack.exceptions.MisconfigurationException('smtp_tlscafile')
+        if not self.socks_host:
+            raise whisperBack.exceptions.MisconfigurationException('socks_host')
+        if not self.socks_port:
+            raise whisperBack.exceptions.MisconfigurationException('socks_port')
 
     def execute_threaded(self, func, args, progress_callback=None, 
                            finished_callback=None, polling_freq=100):
@@ -280,6 +286,7 @@ class WhisperBack(object):
         self.execute_threaded(func=whisperBack.mail.send_message_tls,
                               args=(self.from_address, self.to_address,
                                     mime_message, self.smtp_host,
-                                    self.smtp_port, self.smtp_tlscafile),
+                                    self.smtp_port, self.smtp_tlscafile, 
+                                    self.socks_host, self.socks_port),
                               progress_callback=progress_callback,
                               finished_callback=finished_callback)
-- 
2.1.4

