Socks proxy support

This commit is contained in:
TreeNode
2014-12-10 23:37:34 +02:00
parent 150fd1b5bc
commit 50b80b2a08
3 changed files with 40 additions and 0 deletions

View File

@ -15,6 +15,8 @@ import imaplib
import mimetypes
import poplib
import re
import socks
import socket
from datetime import timedelta
from email.header import decode_header
@ -84,6 +86,17 @@ def process_queue(q, quiet=False):
if not quiet:
print "Processing: %s" % q
if q.socks_proxy_type and q.socks_proxy_host and q.socks_proxy_port:
proxy_type = {
'socks4': socks.SOCKS4,
'socks5': socks.SOCKS5,
}.get(q.socks_proxy_type)
socks.set_default_proxy(proxy_type=proxy_type, addr=q.socks_proxy_host, port=q.socks_proxy_port)
socket.socket = socks.socksocket
else:
socket.socket = socket._socketobject
email_box_type = settings.QUEUE_EMAIL_BOX_TYPE if settings.QUEUE_EMAIL_BOX_TYPE else q.email_box_type
if email_box_type == 'pop3':