Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104930
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2016-03-15 03:48 -0700 |
| Message-ID | <2f0a6e59-a636-4c65-9181-df6de05035a6@googlegroups.com> (permalink) |
| Subject | Fetch Gmail Archieved messages |
| From | Arshpreet Singh <arsh840@gmail.com> |
Hi, I am using imaplib to fetch Gmail's Inbox Archived message but results are not that much accurate. Here is code+logic:
def inbox_week():
import imaplib
EMAIL = 'myusername@gmail.com'
PASSWORD = 'mypassword'
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login( EMAIL, PASSWORD )
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.select("[Gmail]/All Mail")
interval = (date.today()-timedelta(d)).strftime("%d-%b-%Y")
_, data = mail.uid('search', None,'(SENTSINCE{date})'.format(date=interval))
for num in data[0].split():
_, data = mail.uid('fetch', num, '(BODY.PEEK[])')
for response_part in data:
if isinstance(response_part, tuple):
msg = email.message_from_string(response_part[1])
for header in ['to']:
# This is logic for inbox-archieved messages
if (EMAIL in str(msg[header]) in str(msg[header])):
main_tuple = email.utils.parsedate_tz(msg['Date'])
yield main_tuple
I am not sure how to get the list of only Inbox-messages as well as Sentbox messages from [All-mail]. Do I need to any other library ?
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Fetch Gmail Archieved messages Arshpreet Singh <arsh840@gmail.com> - 2016-03-15 03:48 -0700
Re: Fetch Gmail Archieved messages Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-15 10:02 -0700
Re: Fetch Gmail Archieved messages Arshpreet Singh <arsh840@gmail.com> - 2016-03-17 21:14 -0700
Re: Fetch Gmail Archieved messages Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-17 22:44 -0700
Re: Fetch Gmail Archieved messages Arshpreet Singh <arsh840@gmail.com> - 2016-03-18 07:19 -0700
Re: Fetch Gmail Archieved messages Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-18 17:08 -0700
Re: Fetch Gmail Archieved messages Arshpreet Singh <arsh840@gmail.com> - 2016-03-20 12:56 -0700
Re: Fetch Gmail Archieved messages Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-20 23:06 +0000
csiph-web