Google Apps Script unexpectedly started throwing "wrong mime type errors"

I have a script that processes a shared mailbox and forwards it to a different email (based on things like the original β€œTo:” header for different people. It has been working fine for several months as being more flexible (and right now, reliable) replacing gmail filters.

Logic is basically

  • Read each raw message in your inbox
  • See to whom it was sent to: (for example, support@domain.com ), which is an alias for this gmail mailbox.
  • Get a list of prospective recipients (as part of our site)
  • For each of them send a message to
  • Mark this message as processed, so it will not be redirected next time

We recently received an email that seems to be causing a strange error the moment the message is being forwarded. Error: "Invalid mime type. (Line 123, file" Code "). Line 123 script reads:

// subject: removes the 'Fwd:' prefix which we don't need, and adds the original target email in square brackets, and sets the replyTo for easy processing really && msg.forward(rcvr, {subject: msg.getSubject() + " [" + thisTo + "]", replyTo: msg.getFrom()}); 

Here's a summary of the interesting bits:

  • really is just logical, so we can run dry runs for testing
  • msg set to the currently processed message and is of type GmailMessage
  • rcvr is a string with the recipient's email address.
  • thisTo is a string containing the original To: header

This post is a multi-user plaintext and html mime post. It displays fine in gmail, and I can send it there without a problem. So, can anyone shed some light on what the script engine is complaining about? Raw email looks like this (with some bits extracted to ensure confidentiality), in case this helps to disable it:

 Delivered-To: XXXX@YYYY.com Received: by 10.182.155.73 with SMTP id vj5sqase239pbc; Wed, 26 Jun 2013 08:50:48 -0700 (PDT) X-Received: by 10.68.166.5 with SMTP id zc5m425et238pbb.16.1372261847795; Wed, 26 Jun 2013 08:50:47 -0700 (PDT) Return-Path: < support@ZZZZ.com > Received: from mail.ZZZZ.com (mail.ZZZZ.com. [64.78.193.232]) by mx.google.com with ESMTP id vj5sqwefwe239pbc.316.2013.06.26.08.50.47 for <multiple recipients>; Wed, 26 Jun 2013 08:50:47 -0700 (PDT) Received-SPF: pass (google.com: domain of support@ZZZZ.com designates aa.bb.cc.dd as permitted sender) client-ip=aa.bb.cc.dd; Authentication-Results: mx.google.com; spf=pass (google.com: domain of support@ZZZZ.com designates aa.bb.cc.dd as permitted sender) smtp.mail=support@ZZZZ.com Date: Wed, 26 Jun 2013 09:50:46 -0600 To: AAAA@YYYY.com , XXXX@YYYY.com From: ZZZZ < support@ZZZZ.com > Reply-to: ZZZZ < support@ZZZZ.com > Subject: ZZZZ (Order #00412744) Message-ID: < 805b426783f23fec38ddafb002ce40b@admin.ZZZZ.com > X-Priority: 3 X-Mailer: PHPMailer 5.1 (phpmailer.sourceforge.net) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="b1_805b426783ff4601fbe72afb002ce40b" --b1_805b426783ff4601fbe72afb002ce40b Content-Type: text/plain; charset = "utf-8" Content-Transfer-Encoding: 7bit Hello Andy, [SNIP] and destroy all copies of the original message. Thank You --b1_805b426783ff4601fbe72afb002ce40b Content-Type: text/html; charset = "utf-8" Content-Transfer-Encoding: 7bit <html> <head> </head> [SNIP] and destroy all copies of the original message. Thank You</span></font></p></td></tr></tbody></table></body> </html> --b1_805b426783ff4601fbe72afb002ce40b-- 

Thank you very much,

Dave

+6
source share

Source: https://habr.com/ru/post/948333/


All Articles