How to delete all emails not in the important or sent folder?

My inbox has the most e-mail messages than in important and sent inboxes. I want to delete all letters that are not in the important or sent mailbox.

I cannot perform the following steps: 1) Delete all emails in the entire mailbox (when I delete all emails in the entire mailbox, all letters in important and sent mailboxes will be deleted at the same time)
2) and copy the letters from important and sent mailboxes.

How can I write code for this? The problem may become another form:

how can I make a copy of the letters in my gmailbox: "[Gmail] / & kc 2JgQ-" in the local directory g: \ mygmail?

There are 5 letters in my gmail inbox, I save them all in g: \ mygmails and name them as 0th.myemail 1th.myemail 2th.myemail 3th.myemail 4th.myemail with the following code, now how can I read them with thunderbird or email, i don't want to write my own code to read them?

import email,imaplib
att_path="g:\\mygmails\\"
user="xxxx"
password="yyyy"
con=imaplib.IMAP4_SSL('imap.gmail.com')
con.login(user,password)
con.select('INBOX')
resp, items = con.search(None, "ALL")  
items = items[0].split() 
for id,num in enumerate(items):
    resp, data = con.fetch(num, "(RFC822)") 
    data=data[0][1]
    fp = open(att_path+str(id)+"th"+".myemail", 'wb')
    fp.write(data)
    fp.close()
+4
source share
2 answers

After some google search, I found the github repository that provides a module for this. This is not well documented, but the source code is very easy to read, so it is not a significant loss at all.

, , .

, , , -, set.

- , , .

:, python, :

# Global Variables
username, password, mailboxname = '', '', '[Gmail]/&kc 2JgQ-'

# Set up
import gmail
g = gmail.Gmail()
g.login(username, password)

# Actual code.
emails = []
for email in g.mailbox(mailboxname).mail():
    emails.append(email.fetch())

# Tear down.
g.logout()

, , , python ( python emails) mailboxname gmail username. - ().

+3

Windows_PowerShell , . Mail_User_Agent API - . Powershell ( - Microsoft) IE ( , ) .    , API - - . , - . .

0

All Articles