?

Log in

No account? Create an account
entries friends calendar profile http://web.figure1.net/~jlindqui Previous Previous Next Next
Bandage for MySpace mail misbehavior - Jason Lindquist
Idle ramblings of an idle mind
jlindquist
jlindquist
Bandage for MySpace mail misbehavior
Look, we all know the people responsible for designing and running MySpace are a bunch of douchebags. This isn't just me bitching, it's my opinion as an experienced, professional software developer. The people that make that system go should never be allowed near a keyboard--unless it's being used to beat them. Looking at just their mail notifications, here's the three brain-dead things they do that make it difficult to manage their mail:

One: They MIME-encode headers per RFC-1522 when it's not neccessary. Look, fuckers, if the charset is US-ASCII or ISO-8859-1, LEAVE IT BE. Many non-GUI tools will decode the Subject: header if it's done like this, but they don't do From: or Reply-To:. So all I get in mutt's directory view is a bunch of messages from =?iso-8859-1?q?.

Two: The message body is either text/plain or text/html. Whee. By definition, that's 7-bit ASCII and is passable by any standards-compliant mail transport engine. But MySpace MIME encodes it anyways.

Three: Once decoded? Those message bodies use CR-LF line terminators. Pick one, cockbandits! (If they base64 encode the bodies, at least mimencode can auto-convert them. It won't do it to quoted-printable bodies, though.

No, the "easy solution" of ignoring MySpace isn't feasible. Sadly, I still have too many people I need to keep in touch with who can't break the habit.


Here's the recipe to strip the encoding out of the headers:

### Strip quoted-printable headers

:0
* ^From:.*=\?[^?]+\?[qb]\?[^?]+\?=.*
{
  MYSUBJECT = `formail -c -xFrom: | mimeheaddecode`

  :0 fh
  | $FORMAIL -t -IFrom: -A"From: $MYSUBJECT"
}

:0
* ^Subject:.*=\?[^?]+\?[qb]\?[^?]+\?=.*
{
  MYSUBJECT = `formail -c -xSubject: | mimeheaddecode`

  :0 fh
  | $FORMAIL -t -ISubject: -A"Subject: $MYSUBJECT"
}

:0
* ^Reply-To:.*=\?[^?]+\?[qb]\?[^?]+\?=.*
{
  MYSUBJECT = `formail -c -xReply-To: | mimeheaddecode`

  :0 fh
  | $FORMAIL -t -IReply-To: -A"Reply-To: $MYSUBJECT"
}


mimeheaddecode is a perl script found in $PATH borrowed from Alex Benenson:
#!/usr/local/bin/perl

while (<>) {
  chomp;
  s/^[ \t]//;
  foreach (split(/(=[?].*?[?][BQ][?].*?[?]=)/i)) {
    if (($charset, $encoding, $txt) = /=[?](.*?)[?]([bq])[?](.*?)[?]=/i) {
      $encoding =~ tr/[BQ]/[bq]/;
      open PIPE, "echo '$txt' | mimencode -u -$encoding |";
      $_ = ;
      close PIPE;
      chomp;
      }
    s/[[:^ascii:]]//g;
    print $_;
  }
}


I added the 4th line from the end, which strips all non-ASCII characters, since mimencode's output is 8-bit.

The last recipe takes care of decoding the bodies, straight out of the procmailex(5) manpage:
### Decode quoted-printable and base64 text bodies
### MySpace likes to send this shit.  What a fucking waste.

:0
* ^Content-Type: *text/(plain|html)
{
  :0 fbw
  * ^Content-Transfer-Encoding: *quoted-printable
  | mimencode -u -q -p

     :0 Afhw
     | formail -I "Content-Transfer-Encoding: 8bit"

  :0 fbw
  * ^Content-Transfer-Encoding: *base64
  | mimencode -u -b -p

     :0 Afhw
     | formail -I "Content-Transfer-Encoding: 8bit"
}

Tags: , , ,

Leave a comment