How to download a gmail attachment?
<p>I am trying to download email attachments from Gmail using python using code shared on link</p>

<p><a href="https://gist.github.com/baali/2633554" rel="nofollow">https://gist.github.com/baali/2633554</a></p>

<p>I want to apply time filter + subject filter and download the attachment. For example all files received in last 24 hours, etc.
Can anyone please share code or reading material to apply advance filter for email selection.</p>

<p>Based on the script you linked, add the following lines to filter emails on date and subject:</p>

<pre><code>from datetime import datetime

day = '2016-09-06'
subject = 'Your command is available'
look_for = '(SENTSINCE {0} SUBJECT "{1}")'.format(
    datetime.strptime(day, '%Y-%m-%d').strftime('%d-%b-%Y'), subject)

typ, data = imapSession.search(None, 'ALL')  # Line 25
</code></pre>

<p>You will have to customize variables but you have a working example here.
BTW, you should have a look at this <a href="https://gist.github.com/mjseeley/5e182c0c29dde014cfac" rel="nofollow">fork</a>, it seems more up to date. </p>

python gmail attachment