<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Python Gmail imaplib search subject get attachments</title>
	<atom:link href="http://bookmarks.honewatson.com/2009/08/11/python-gmail-imaplib-search-subject-get-attachments/feed/" rel="self" type="application/rss+xml" />
	<link>http://bookmarks.honewatson.com/2009/08/11/python-gmail-imaplib-search-subject-get-attachments/</link>
	<description>I bring you the best from the web - random bookmarks.</description>
	<lastBuildDate>Fri, 14 Oct 2011 13:38:49 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Eric Beringer</title>
		<link>http://bookmarks.honewatson.com/2009/08/11/python-gmail-imaplib-search-subject-get-attachments/#comment-1469</link>
		<dc:creator><![CDATA[Eric Beringer]]></dc:creator>
		<pubDate>Thu, 09 Jun 2011 22:58:36 +0000</pubDate>
		<guid isPermaLink="false">http://bookmarks.honewatson.com/2009/08/11/python-gmail-imaplib-search-subject-get-attachments/#comment-1469</guid>
		<description><![CDATA[I know this is old, but just in case someone comes across this,

placing: m.select() on the line before the search solves this problem.

:)]]></description>
		<content:encoded><![CDATA[<p>I know this is old, but just in case someone comes across this,</p>
<p>placing: m.select() on the line before the search solves this problem.<br />
 <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: denbeigh2000</title>
		<link>http://bookmarks.honewatson.com/2009/08/11/python-gmail-imaplib-search-subject-get-attachments/#comment-1459</link>
		<dc:creator><![CDATA[denbeigh2000]]></dc:creator>
		<pubDate>Tue, 03 May 2011 22:18:00 +0000</pubDate>
		<guid isPermaLink="false">http://bookmarks.honewatson.com/2009/08/11/python-gmail-imaplib-search-subject-get-attachments/#comment-1459</guid>
		<description><![CDATA[&gt;Hi,
&gt;I’m trying to do something similar but I get an error:
&gt;In [67]: resp, items = m.search(None, searchString)
&gt;(…)
&gt;error: command SEARCH illegal in state AUTH, only allowed in states &gt;SELECTED
&gt;Do you know what might happened??

m.select()]]></description>
		<content:encoded><![CDATA[<p>&gt;Hi,<br />
&gt;I’m trying to do something similar but I get an error:<br />
&gt;In [67]: resp, items = m.search(None, searchString)<br />
&gt;(…)<br />
&gt;error: command SEARCH illegal in state AUTH, only allowed in states &gt;SELECTED<br />
&gt;Do you know what might happened??</p>
<p>m.select()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hugo</title>
		<link>http://bookmarks.honewatson.com/2009/08/11/python-gmail-imaplib-search-subject-get-attachments/#comment-1375</link>
		<dc:creator><![CDATA[hugo]]></dc:creator>
		<pubDate>Mon, 06 Sep 2010 15:58:09 +0000</pubDate>
		<guid isPermaLink="false">http://bookmarks.honewatson.com/2009/08/11/python-gmail-imaplib-search-subject-get-attachments/#comment-1375</guid>
		<description><![CDATA[Hi there,

I get a error like:
imaplib.error: command SEARCH illegal in state AUTH, only allowed in states SELECTED

any suggestions?
tx

hugo]]></description>
		<content:encoded><![CDATA[<p>Hi there,</p>
<p>I get a error like:<br />
imaplib.error: command SEARCH illegal in state AUTH, only allowed in states SELECTED</p>
<p>any suggestions?<br />
tx</p>
<p>hugo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leo</title>
		<link>http://bookmarks.honewatson.com/2009/08/11/python-gmail-imaplib-search-subject-get-attachments/#comment-1335</link>
		<dc:creator><![CDATA[Leo]]></dc:creator>
		<pubDate>Mon, 22 Mar 2010 21:49:38 +0000</pubDate>
		<guid isPermaLink="false">http://bookmarks.honewatson.com/2009/08/11/python-gmail-imaplib-search-subject-get-attachments/#comment-1335</guid>
		<description><![CDATA[I&#039;m using the following to get the email attachment:
import poplib
    from email.Parser import Parser
    pop3 = poplib.POP3(mail_host)
    pop3.user(mail_user)
    pop3.pass_(mail_passwd)

    num = len(pop3.list()[1])

    if num &gt; 0:
        for i in range(1, num+1):
            str = string.join(pop3.top(i, 55)[1], &quot;\n&quot;)
            msg = Parser().parsestr(str)
            n=0
            text=&#039;&#039;
            #Check if any attachments at all
            if msg.get_content_maintype() != &#039;multipart&#039;:
                print &#039;No attachments in message&#039;
                return
    
            for part in msg.walk():
                if n==1:
                    text=part.get_payload()
                n+=1
                if part.get_content_maintype() == &#039;multipart&#039;:
                    continue
                if part.get(&#039;Content-Disposition&#039;) is None:
                    continue
                filename = part.get_filename()
                counter = 1
                if not filename:
                    filename = &#039;part-%03d%s&#039; % (counter, &#039;bin&#039;)
                    counter += 1
                att_path = os.path.join(detach_dir, filename)
                if not os.path.isfile(att_path) :
                    fp = open(att_path, &#039;wb&#039;)
                    fp.write(part.get_payload(decode=True))
                    fp.close()
                
            From=msg[&#039;From&#039;]
            Subject=msg[&#039;subject&#039;]
            #parse &#039;from&#039; text
            if From.find(&#039;&lt;&#039;)!=-1:
                start=From.find(&#039;&#039;)
                From=From[(start+1):end]
            body=text.split(&#039;\n&#039;)
            emailBody=text
        #pop3.dele(i)

It seems to work fine, but when I look at the resulting file (XLS file), it&#039;s 1k big and can&#039;t even be opened. What am I doing wrong?]]></description>
		<content:encoded><![CDATA[<p>I&#8217;m using the following to get the email attachment:<br />
import poplib<br />
    from email.Parser import Parser<br />
    pop3 = poplib.POP3(mail_host)<br />
    pop3.user(mail_user)<br />
    pop3.pass_(mail_passwd)</p>
<p>    num = len(pop3.list()[1])</p>
<p>    if num &gt; 0:<br />
        for i in range(1, num+1):<br />
            str = string.join(pop3.top(i, 55)[1], &#8220;\n&#8221;)<br />
            msg = Parser().parsestr(str)<br />
            n=0<br />
            text=&#8221;<br />
            #Check if any attachments at all<br />
            if msg.get_content_maintype() != &#8216;multipart&#8217;:<br />
                print &#8216;No attachments in message&#8217;<br />
                return</p>
<p>            for part in msg.walk():<br />
                if n==1:<br />
                    text=part.get_payload()<br />
                n+=1<br />
                if part.get_content_maintype() == &#8216;multipart&#8217;:<br />
                    continue<br />
                if part.get(&#8216;Content-Disposition&#8217;) is None:<br />
                    continue<br />
                filename = part.get_filename()<br />
                counter = 1<br />
                if not filename:<br />
                    filename = &#8216;part-%03d%s&#8217; % (counter, &#8216;bin&#8217;)<br />
                    counter += 1<br />
                att_path = os.path.join(detach_dir, filename)<br />
                if not os.path.isfile(att_path) :<br />
                    fp = open(att_path, &#8216;wb&#8217;)<br />
                    fp.write(part.get_payload(decode=True))<br />
                    fp.close()</p>
<p>            From=msg['From']<br />
            Subject=msg['subject']<br />
            #parse &#8216;from&#8217; text<br />
            if From.find(&#8216;&lt;&#039;)!=-1:<br />
                start=From.find(&#039;&#8217;)<br />
                From=From[(start+1):end]<br />
            body=text.split(&#8216;\n&#8217;)<br />
            emailBody=text<br />
        #pop3.dele(i)</p>
<p>It seems to work fine, but when I look at the resulting file (XLS file), it&#8217;s 1k big and can&#8217;t even be opened. What am I doing wrong?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anders</title>
		<link>http://bookmarks.honewatson.com/2009/08/11/python-gmail-imaplib-search-subject-get-attachments/#comment-1322</link>
		<dc:creator><![CDATA[anders]]></dc:creator>
		<pubDate>Wed, 10 Mar 2010 12:55:12 +0000</pubDate>
		<guid isPermaLink="false">http://bookmarks.honewatson.com/2009/08/11/python-gmail-imaplib-search-subject-get-attachments/#comment-1322</guid>
		<description><![CDATA[Hi,

I&#039;m trying to do something similar but I get an error:


In [67]: resp, items = m.search(None, searchString)

(...)

error: command SEARCH illegal in state AUTH, only allowed in states SELECTED

Do you know what might happened??]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I&#8217;m trying to do something similar but I get an error:</p>
<p>In [67]: resp, items = m.search(None, searchString)</p>
<p>(&#8230;)</p>
<p>error: command SEARCH illegal in state AUTH, only allowed in states SELECTED</p>
<p>Do you know what might happened??</p>
]]></content:encoded>
	</item>
</channel>
</rss>

