title: Python - Connect to IMAP through Socks
body: <p>I'm looking for solution connect to IMAP using Socks proxy. The most elegant way that I found it's a wrapper of PySocks of IMAP4 lib (you can find gist with this code here: <a href="https://gist.github.com/sstevan/efccf3d5d3e73039c21aa848353ff52f" rel="nofollow noreferrer">https://gist.github.com/sstevan/efccf3d5d3e73039c21aa848353ff52f</a>).</p>
  <p>The problem that I couldn't make it works in python3. For me it looks like there is an issue with inherit:</p>
  <p><strong>Main script calls SocksIMAP4SSL wrapper</strong></p>
  <pre><code>    mailbox = SocksIMAP4SSL(host=imap_server, port=imap_port,
                              proxy_addr=proxy_addr, proxy_port=proxy_port, proxy_type=proxy_type)
  </code></pre>
  <p><strong>Implementation of init of SocksIMAP4SSL</strong></p>
  <pre><code>    def __init__(self, host='', port=IMAP4_SSL_PORT, keyfile=None, certfile=None, ssl_context=None, proxy_addr=None,
                   proxy_port=None, rdns=True, username=None, password=None, proxy_type=&quot;socks5&quot;):
          .......
          SocksIMAP4.__init__(self, host, port, proxy_addr=proxy_addr, proxy_port=proxy_port,
                              rdns=rdns, username=username, password=password, proxy_type=proxy_type)
  </code></pre>
  <p><strong>Implementation of init of SocksIMAP4</strong></p>
  <pre><code>    def __init__(self, host, port=IMAP4_PORT, proxy_addr=None, proxy_port=None,
                   rdns=True, username=None, password=None, proxy_type=&quot;socks5&quot;):
  
          self.proxy_addr = proxy_addr
          self.proxy_port = proxy_port
          self.rdns = rdns
          self.username = username
          self.password = password
          self.proxy_type = SocksIMAP4.PROXY_TYPES[proxy_type.lower()]
  
          IMAP4.__init__(self, host, port)
  </code></pre>
  <p>When I run this code I get an error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/Users/lavidaloca/Programming/Projects/twitter_checkmat/twitter.py&quot;, line 691, in &lt;module&gt;
      hotmail = Hotmail('similargatorade3@hotmail.com', 'C9C48RyO', proxy)
    File &quot;/Users/lavidaloca/Programming/Projects/twitter_checkmat/hotmail.py&quot;, line 78, in __init__
      self.mail = SocksIMAP4SSL(host=self.imap_server, port=self.imap_port, proxy_addr=proxy.host, proxy_port=proxy.port, username=proxy.login, password=proxy.password)
    File &quot;/Users/lavidaloca/Programming/Projects/twitter_checkmat/hotmail.py&quot;, line 59, in __init__
      SocksIMAP4.__init__(self, host, port, proxy_addr=proxy_addr, proxy_port=proxy_port,
    File &quot;/Users/lavidaloca/Programming/Projects/twitter_checkmat/hotmail.py&quot;, line 34, in __init__
      IMAP4.__init__(self, host, port)
    File &quot;/opt/homebrew/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/imaplib.py&quot;, line 202, in __init__
      self.open(host, port, timeout)
  TypeError: open() takes from 1 to 3 positional arguments but 4 were given
  </code></pre>
  <p>It looks like by someway original <strong>init</strong> method of IMAP4 library receives init args of subclasses.</p>
  <p>I'll be appreciate for your help if you give me idea how I can fix this code or give me another solution for make connection to imap over socks.</p>