Ok, so I'm trying to save pdf attachments sent to a specific account to a specific network folder but I'm stuck at the attachment part. I've got the following code to pull in the unseen messages, but I'm not sure how to get the "parts" to stay intact. I think I can maybe figure this out if I can figure out how to keep the email message complete. I never make it past "Made it to walk" output. All testing emails in this account include pdf attachments. Thanks in advance.
import imaplib
import email
import regex
import re
user = 'some_user'
password = 'gimmeAllyerMoney'
server = imaplib.IMAP4_SSL('mail.itsstillmonday.com', '993')
server.login(user, password)
server.select('inbox')
msg_ids=[]
resp, messages = server.search(None, 'UNSEEN')
for message in messages[0].split():
typ, data = server.fetch(message, '(RFC822)')
msg= email.message_from_string(str(data[0][1]))
#looking for 'Content-Type: application/pdf
for part in msg.walk():
print("Made it to walk")
if part.is_multipart():
print("made it to multipart")
if part.get_content_maintype() == 'application/pdf':
print("made it to content")
maintype
would be justapplication
for something withContent-type: application/pdf
Content-Type: multipart
appears in the message header. I will make the update for the application/pdf piece, too.