Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3315312
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:20:07+00:00 2026-05-17T22:20:07+00:00

I am extracting emails from Gmail using the following: def getMsgs(): try: conn =

  • 0

I am extracting emails from Gmail using the following:

def getMsgs():
 try:
    conn = imaplib.IMAP4_SSL("imap.gmail.com", 993)
  except:
    print 'Failed to connect'
    print 'Is your internet connection working?'
    sys.exit()
  try:
    conn.login(username, password)
  except:
    print 'Failed to login'
    print 'Is the username and password correct?'
    sys.exit()

  conn.select('Inbox')
  # typ, data = conn.search(None, '(UNSEEN SUBJECT "%s")' % subject)
  typ, data = conn.search(None, '(SUBJECT "%s")' % subject)
  for num in data[0].split():
    typ, data = conn.fetch(num, '(RFC822)')
    msg = email.message_from_string(data[0][1])
    yield walkMsg(msg)

def walkMsg(msg):
  for part in msg.walk():
    if part.get_content_type() != "text/plain":
      continue
    return part.get_payload()

However, some emails I get are nigh impossible for me to extract dates (using regex) from as encoding-related chars such as ‘=’, randomly land in the middle of various text fields. Here’s an example where it occurs in a date range I want to extract:

Name: KIRSTI Email:
kirsti@blah.blah Phone #: + 999
99995192 Total in party: 4 total, 0
children Arrival/Departure: Oct 9=
,
2010 – Oct 13, 2010 – Oct 13, 2010

Is there a way to remove these encoding characters?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:20:08+00:00Added an answer on May 17, 2026 at 10:20 pm

    You could/should use the email.parser module to decode mail messages, for example (quick and dirty example!):

    from email.parser import FeedParser
    f = FeedParser()
    f.feed("<insert mail message here, including all headers>")
    rootMessage = f.close()
    
    # Now you can access the message and its submessages (if it's multipart)
    print rootMessage.is_multipart()
    
    # Or check for errors
    print rootMessage.defects
    
    # If it's a multipart message, you can get the first submessage and then its payload
    # (i.e. content) like so:
    rootMessage.get_payload(0).get_payload(decode=True)
    

    Using the “decode” parameter of Message.get_payload, the module automatically decodes the content, depending on its encoding (e.g. quoted printables as in your question).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using C# how should I go about extracting titles subtitles and paragraphs from a
I have an xml file from which I am extracting html using LINQ to
I'm extracting emails from a database where they're stored as strings. I need to
Is there a good library for extracting text from a PDF? I'm willing to
Closed as duplicate of What are some ways to protect emails on websites from
I commonly find myself extracting common behavior out of classes into helper/utility classes that
Is there a way to combine a previous translation when extracting the csv file
I'm currently modifying my regex for this: Extracting email addresses in an html block
So i am working with some email header data, and for the to:, from:,
I'm trying to send an email using JavaMail API. I have jdk 1.5 installed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.