Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion MIME-encoded messages in a digest (was: Re: Deleting unwanted message headers from saved email)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dave Gibson  
View profile  
 More options Sep 20 2012, 9:42 am
Newsgroups: comp.lang.awk
From: dave.gma+news...@googlemail.com.invalid (Dave Gibson)
Date: Thu, 20 Sep 2012 14:40:04 +0100
Local: Thurs, Sep 20 2012 9:40 am
Subject: MIME-encoded messages in a digest (was: Re: Deleting unwanted message headers from saved email)

Steve Hayes <hayes...@telkomsa.net> wrote:
> On Wed, 19 Sep 2012 12:56:13 +0100, dave.gma+news...@googlemail.com.invalid
> (Dave Gibson) wrote:

>>Steve Hayes <hayes...@telkomsa.net> wrote:
>>> I'm not sure what that X-CC-Diagnistic thingy is. It seems big.

>>The gibberish is the message body encoded as base64 -- it's not
>>associated with a specific header.

> I've just been checking some of the messages I've been trying to save.

> These ones are hard to read and save:

> Content-Type: text/plain; charset="utf-8"
> Content-Transfer-Encoding: base64

> These are not quite as hard to read or save, but still cause some
> problems:

> Content-Type: text/plain; charset=utf-8
> Content-Transfer-Encoding: quoted-printable

> These ones are easy to read and save:

> Content-Type: text/plain; charset="us-ascii"
> Content-Transfer-Encoding: 7bit

> The ones that are hardest to read and save appear to be produced
> by Windows Live Mail.

They're standard MIME encodings intended to prevent message data being
corrupted in transit.

  <http://tools.ietf.org/html/rfc2045>

Your mail user agent should be able to convert them to local format
while saving them.

Have a look at these:

  <http://www.convertstring.com/EncodeDecode/Base64Decode>
  <http://www.convertstring.com/EncodeDecode/QuotedPrintableDecode>

> Perhaps one could tell awk to delete such messages.

Wouldn't you rather decode them?

  <http://www.fourmilab.ch/webtools/base64/>

Anyway, assuming messages are in a digest, separated by lines containing
the string "-- End --" and none of them are multipart messages.

#v+
----script begins on next line
/^-- End --/ {
  if (!b64)
    print
  body = 0
  b64 = 0
  next

}

b64 { next }

!body && /^$/ {
  for (n = 1; n <= hlines; n++)
    print header[n]
  hlines = 0
  body = 1  

}

body { print ; next }

/^[Cc][Oo][Nn][Tt][Ee][Nn][Tt]-[Tt][Rr][Aa][Nn][Ss][Ff][Ee][Rr]-[Ee][Nn][Cc ][Oo][Dd][Ii][Nn][Gg]: [Bb][Aa][Ss][Ee]64/ {
  b64 = 1
  hlines = 0
  next

}

{ header[++hlines] = $0 }
----script ends on previous line
#v-

>  Would it also
> be able to convert "quoted printable" into something more readable?

Perl has modules for dealing with various mail formats so may well be
better suited to your requirements.

#v+
----script begins on next line
BEGIN {
  hex["0"] = 0  ; hex["1"] = 1  ; hex["2"] = 2  ; hex["3"] = 3
  hex["4"] = 4  ; hex["5"] = 5  ; hex["6"] = 6  ; hex["7"] = 7
  hex["8"] = 8  ; hex["9"] = 9  ; hex["A"] = 10 ; hex["B"] = 11
  hex["C"] = 12 ; hex["D"] = 13 ; hex["E"] = 14 ; hex["F"] = 15
  for (n = 0 ; n <= 255; n++)
    ch[n] = sprintf("%c", n)

}

/^-- End --/ { qp = 0 ; body = 0 }

/^$/ { body = 1 }

!body && /^[Cc][Oo][Nn][Tt][Ee][Nn][Tt]-[Tt][Rr][Aa][Nn][Ss][Ff][Ee][Rr]-[Ee][Nn][Cc ][Oo][Dd][Ii][Nn][Gg]: [Qq][Uu][Oo][Tt][Ee][Dd]-[Pp][Rr][Ii][Nn][Tt][Aa][Bb][Ll][Ee]/ {
  qp = 1
  $NF = "8bit"

}

body && qp && /=/ {
  s = $0
  # Brackets '[', ']' on next line contain a space and a tab
  u = sub(/=[   ]*$/, "", s)
  t = ""
  while (match(s, /=[0-9A-F][0-9A-F]/)) {
    t = t substr(s, 1, RSTART - 1) \
        ch[hex[substr(s, RSTART + 1, 1)] * 16 + hex[substr(s, RSTART + 2, 1)]]
    s = substr(s, RSTART + RLENGTH)
  }
  $0 = t s
  if (u) {
    printf "%s", $0
    next
  }

}

{ print }
----script ends on previous line
#v-

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.