Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Choosing Source Address to Bind Socket to in IMAP Client

Reply
Thread Tools

Choosing Source Address to Bind Socket to in IMAP Client

 
 
brintoul@controlledthinking.com
Guest
Posts: n/a
 
      11-20-2012
Hello:

I have a multihomed machine that I would like to run the Python imaplib's IMAP4 client on. I would like to be able to specify which interface the underlying socket will bind to as its source address. How could I best do this?

Thanks for any help...
 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      11-20-2012
On Wed, Nov 21, 2012 at 8:14 AM, <(E-Mail Removed)> wrote:
> Hello:
>
> I have a multihomed machine that I would like to run the Python imaplib's IMAP4 client on. I would like to be able to specify which interface the underlying socket will bind to as its source address. How could I best do this?


You're referring to this function?

http://docs.python.org/3.3/library/i...#imaplib.IMAP4

The docs suggest that you can simply pass it a parameter to specify
the address to bind to. (Note that you bind to addresses, not
interfaces. Figuring out which interface has which address is a
separate issue.)

ChrisA
 
Reply With Quote
 
 
 
 
Prasad, Ramit
Guest
Posts: n/a
 
      11-20-2012
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

>
> Hello:
>
> I have a multihomed machine that I would like to run the Python imaplib's IMAP4 client on. I would like to be
> able to specify which interface the underlying socket will bind to as its source address. How could I best do
> this?


One assumes by programming.


>
> Thanks for any help...


You are quite welcome.

On a less flippant note, maybe some links would help you
get started.

http://www.doughellmann.com/PyMOTW/imaplib/
http://yuji.wordpress.com/2011/06/22...le-with-gmail/
http://docs.python.org/2/library/imaplib.html


~Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
 
Reply With Quote
 
brintoul@controlledthinking.com
Guest
Posts: n/a
 
      11-20-2012
On Tuesday, November 20, 2012 1:48:46 PM UTC-8, Chris Angelico wrote:
> On Wed, Nov 21, 2012 at 8:14 AM, <brintoul at controlledthinking.com> wrote:
>
> > Hello:

>
> >

>
> > I have a multihomed machine that I would like to run the Python imaplib's IMAP4 client on. I would like to be able to specify which interface the underlying socket will bind to as its source address. How could I best do this?

>
>
>
> You're referring to this function?
>
>
>
> http://docs.python.org/3.3/library/i...#imaplib.IMAP4
>
>
>
> The docs suggest that you can simply pass it a parameter to specify
>
> the address to bind to. (Note that you bind to addresses, not
>
> interfaces. Figuring out which interface has which address is a
>
> separate issue.)
>
>
>
> ChrisA


Unless I'm reading that wrong, that's specifying the address/host to connect to (the destination address) not the source address...
 
Reply With Quote
 
brintoul@controlledthinking.com
Guest
Posts: n/a
 
      11-20-2012
On Tuesday, November 20, 2012 1:48:46 PM UTC-8, Chris Angelico wrote:
> On Wed, Nov 21, 2012 at 8:14 AM, <brintoul at controlledthinking.com> wrote:
>
> > Hello:

>
> >

>
> > I have a multihomed machine that I would like to run the Python imaplib's IMAP4 client on. I would like to be able to specify which interface the underlying socket will bind to as its source address. How could I best do this?

>
>
>
> You're referring to this function?
>
>
>
> http://docs.python.org/3.3/library/i...#imaplib.IMAP4
>
>
>
> The docs suggest that you can simply pass it a parameter to specify
>
> the address to bind to. (Note that you bind to addresses, not
>
> interfaces. Figuring out which interface has which address is a
>
> separate issue.)
>
>
>
> ChrisA


Unless I'm reading that wrong, that's specifying the address/host to connect to (the destination address) not the source address...
 
Reply With Quote
 
brintoul@controlledthinking.com
Guest
Posts: n/a
 
      11-20-2012
On Tuesday, November 20, 2012 1:59:34 PM UTC-8, Prasad, Ramit wrote:
> brintoul at controlledthinking.com wrote:
>
> >

>
> > Hello:

>
> >

>
> > I have a multihomed machine that I would like to run the Python imaplib's IMAP4 client on. I would like to be

>
> > able to specify which interface the underlying socket will bind to as its source address. How could I best do

>
> > this?

>
>
>
> One assumes by programming.
>
>
>
> >

>
> > Thanks for any help...

>
>
>
> You are quite welcome.
>
>
>
> On a less flippant note, maybe some links would help you
>
> get started.
>
>
>
> http://www.doughellmann.com/PyMOTW/imaplib/
>
> http://yuji.wordpress.com/2011/06/22...le-with-gmail/
>
> http://docs.python.org/2/library/imaplib.html
>
>
>
>
>
> ~Ramit
>
>
>
>
>
> This email is confidential and subject to important disclaimers and
>
> conditions including on offers for the purchase or sale of
>
> securities, accuracy and completeness of information, viruses,
>
> confidentiality, legal privilege, and legal entity disclaimers,
>
> available at http://www.jpmorgan.com/pages/disclosures/email.


While I appreciate your attempt at humor, this is not information which helps me. Perhaps you are not familiar with the basics of socket programming.This is all fine and dandy, and it is good to "know what you don't know". If you're interested, look at the third argument to "create_connection": http://docs.python.org/2/library/socket.html
 
Reply With Quote
 
brintoul@controlledthinking.com
Guest
Posts: n/a
 
      11-20-2012
On Tuesday, November 20, 2012 1:59:34 PM UTC-8, Prasad, Ramit wrote:
> brintoul at controlledthinking.com wrote:
>
> >

>
> > Hello:

>
> >

>
> > I have a multihomed machine that I would like to run the Python imaplib's IMAP4 client on. I would like to be

>
> > able to specify which interface the underlying socket will bind to as its source address. How could I best do

>
> > this?

>
>
>
> One assumes by programming.
>
>
>
> >

>
> > Thanks for any help...

>
>
>
> You are quite welcome.
>
>
>
> On a less flippant note, maybe some links would help you
>
> get started.
>
>
>
> http://www.doughellmann.com/PyMOTW/imaplib/
>
> http://yuji.wordpress.com/2011/06/22...le-with-gmail/
>
> http://docs.python.org/2/library/imaplib.html
>
>
>
>
>
> ~Ramit
>
>
>
>
>
> This email is confidential and subject to important disclaimers and
>
> conditions including on offers for the purchase or sale of
>
> securities, accuracy and completeness of information, viruses,
>
> confidentiality, legal privilege, and legal entity disclaimers,
>
> available at http://www.jpmorgan.com/pages/disclosures/email.


While I appreciate your attempt at humor, this is not information which helps me. Perhaps you are not familiar with the basics of socket programming.This is all fine and dandy, and it is good to "know what you don't know". If you're interested, look at the third argument to "create_connection": http://docs.python.org/2/library/socket.html
 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      11-20-2012
On Wed, Nov 21, 2012 at 9:00 AM, <(E-Mail Removed)> wrote:
> On Tuesday, November 20, 2012 1:48:46 PM UTC-8, Chris Angelico wrote:
>> On Wed, Nov 21, 2012 at 8:14 AM, <brintoul at controlledthinking.com> wrote:
>>
>> > I have a multihomed machine that I would like to run the Python imaplib's IMAP4 client on. I would like to be able to specify which interface the underlying socket will bind to as its source address. How could I best do this?

>>
>> You're referring to this function?
>>
>> http://docs.python.org/3.3/library/i...#imaplib.IMAP4
>>
>> The docs suggest that you can simply pass it a parameter to specify
>> the address to bind to. (Note that you bind to addresses, not
>> interfaces. Figuring out which interface has which address is a
>> separate issue.)
>>

>
> Unless I'm reading that wrong, that's specifying the address/host to connect to (the destination address) not the source address...


Ah, whoops! My bad. For some reason I was thinking that was creating a
server socket. Sorry!

Poking around in the source (imaplib.py) shows that it creates a socket here:

class IMAP4:
def _create_socket(self):
return socket.create_connection((self.host, self.port))

Adding a third parameter to create_connection would do what you want.
(Note that this is currently getting one parameter, not two.)

http://docs.python.org/3.3/library/s...ate_connection

My recommendation: Subclass IMAP4 and override this one function.

ChrisA
 
Reply With Quote
 
Prasad, Ramit
Guest
Posts: n/a
 
      11-20-2012
(E-Mail Removed) wrote:

> > > I have a multihomed machine that I would like to run the Python imaplib's IMAP4 client on. I would like to be
> > > able to specify which interface the underlying socket will bind to as its source address. How could I best do
> > > this?

[snip]


> While I appreciate your attempt at humor, this is not information which helps me. Perhaps you are not familiar
> with the basics of socket programming. This is all fine and dandy, and it is good to "know what you don't know".
> If you're interested, look at the third argument to "create_connection":
> http://docs.python.org/2/library/socket.html


Apologies, I misread your question.

According to the imaplib docs, you can subclass IMAP4 andoverride
`IMAP4.open` to create the socket and bind it to the desired interface.
You could also connect using IMAP4 and then close/reopen the socket
inside the IMAP4 connection object.


I hope that is more help,
Ramit


This email is confidential and subject to important disclaimers and
conditions includingon offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
 
Reply With Quote
 
brintoul@controlledthinking.com
Guest
Posts: n/a
 
      11-20-2012
On Tuesday, November 20, 2012 2:41:58 PM UTC-8, Prasad, Ramit wrote:
> brintoul at controlledthinking.com wrote:
>
> Apologies, I misread your question.
>
>
>
> According to the imaplib docs, you can subclass IMAP4 and override
>
> `IMAP4.open` to create the socket and bind it to the desired interface.
>
> You could also connect using IMAP4 and then close/reopen the socket
>
> inside the IMAP4 connection object.
>
> I hope that is more help,
>
> Ramit
>


Thanks, yes, that helps! Just out of curiosity, can you give me a quick link to the docs you are looking at? I'm not seeing anything which gets very specific in the docs for Python 2.7 at docs.python.org ...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM
imap and Tmail. Getting whole email with imap Adam Akhtar Ruby 1 12-15-2008 10:55 PM
net/imap - imap.search "TO" can't find email jasonnaylor Ruby 1 04-16-2008 04:05 AM
Writing IMAP->GMail proxy... Where to go for IMAP RFC help? Jon Fi Ruby 4 10-21-2006 09:00 PM
Curier-IMAP and imap.create() Henrik Ormåsen Ruby 0 08-19-2006 06:29 AM



Advertisments