Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to distinguish sender-generated carriage returns from word wrap auto-generated carriage returns in email body?
    primarykey
    data
    text
    <p>How can I distinguish sender-generated carriage returns from word wrap auto-generated carriage returns in an email body? I'm using Python imaplib to access Gmail and download message bodies like so:</p> <pre><code>user='whoever@gmail.com' pwd='password' m = imaplib.IMAP4_SSL("imap.gmail.com") m.login(user,pwd) m.select("INBOX") resp, items = m.search(None, "ALL") items = items[0].split() messages = [] for emailid in items: resp, data = m.fetch(emailid, "(RFC822)") email_body = data[0][1] mail = email.message_from_string(email_body) for part in mail.walk(): if part.get_content_type() == 'text/plain': body = part.get_payload(decode=1) messages.append(body) </code></pre> <p>I'm focusing on the case of messages received from another Gmail user. The message body text has a number of carriage returns ('\r\n') in it. These fall into two classes: 1) those inserted by the sender of the email, the "true" returns, 2) those created by Gmail word wrapping at ~78 characters, the "false" returns. I want to remove the second class of carriage returns only. I'm sure I could come up with a programmatic approximation that searches for the '\r\n' at a window around every 78th character but that wouldn't be bulletproof and isn't what I want. Interestingly, I notice that when the message displays in Gmail in the web browser, there are not returns for the second class of carriage returns. Gmail somehow knows to remove/not display these specifically. How? Is there some special encoding I'm missing?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload