Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | None | 0 0
  1. import datetime
  2. import email
  3. import imaplib
  4. from mattermostdriver import Driver
  5.  
  6. username = "pakke@hackstage.com"
  7. password = "123hackstage"
  8. mail = imaplib.IMAP4("mail.unoeuro.com", 143)
  9. mail.login(username, password)
  10. mail.select("INBOX")
  11.  
  12. result, data = mail.uid('search', None, "UNSEEN")
  13. i = len(data[0].split())
  14.  
  15. for x in range(i):
  16.     latest_email_uid = data[0].split()[x]
  17.     result, email_data = mail.uid('fetch', latest_email_uid, '(RFC822)')
  18.     raw_email = email_data[0][1]
  19.     raw_email_string = raw_email.decode('utf-8')
  20.     email_message = email.message_from_string(raw_email_string)
  21.  
  22.     # Header Details
  23.     date_tuple = email.utils.parsedate_tz(email_message['Date'])
  24.     if date_tuple:
  25.         local_date = datetime.datetime.fromtimestamp(email.utils.mktime_tz(date_tuple))
  26.         local_message_date = "%s" %(str(local_date.strftime("%a, %d %b %Y %H:%M:%S")))
  27.     email_from = str(email.header.make_header(email.header.decode_header(email_message['From'])))
  28.     email_to = str(email.header.make_header(email.header.decode_header(email_message['To'])))
  29.     subject = str(email.header.make_header(email.header.decode_header(email_message['Subject'])))
  30.  
  31.     # Body details
  32.     for part in email_message.walk():
  33.         if part.get_content_type() == "text/plain":
  34.             body = part.get_payload(decode=True)
  35.         else:
  36.             continue
  37.  
  38.     Pakkemail = "From: %s\nTo: %s\nDate: %s\nSubject: %s\n\nBody: \n\n%s" %(email_from, email_to,local_message_date, subject, body.decode('utf-8'))
  39.     pakkebotto = Driver({
  40.         'url': 'chat.hackstage.com',
  41.         'login_id': 'pakkebot',
  42.         'password': '12haxOr666',
  43.         'scheme': 'http'
  44.     })
  45.  
  46.     pakkebotto.login()
  47.     channel_id = 'rj7j9p4fjjdbfnt3unp5qo5eqy'
  48.  
  49.     pakkebotto.posts.create_post(options={'channel_id': channel_id, 'message': Pakkemail})
  50.  
  51. mail.logout()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement