Преглед на файлове

Added multipart sub-part default content type checks

Jordan Wright преди 9 години
родител
ревизия
669ab2f297
променени са 2 файла, в които са добавени 49 реда и са изтрити 0 реда
  1. 3 0
      email.go
  2. 46 0
      email_test.go

+ 3 - 0
email.go

@@ -143,6 +143,9 @@ func parseMIMEParts(hs textproto.MIMEHeader, b io.Reader) ([]*part, error) {
 			if err != nil {
 				return ps, err
 			}
+			if _, ok := p.Header["Content-Type"]; !ok {
+				p.Header.Set("Content-Type", defaultContentType)
+			}
 			subct, _, err := mime.ParseMediaType(p.Header.Get("Content-Type"))
 			if strings.HasPrefix(subct, "multipart/") {
 				sps, err := parseMIMEParts(p.Header, p)

+ 46 - 0
email_test.go

@@ -243,6 +243,52 @@ func Test_quotedPrintEncode(t *testing.T) {
 	}
 }
 
+func TestMultipartNoContentType(t *testing.T) {
+	raw := []byte(`From: Mikhail Gusarov <dottedmag@dottedmag.net>
+To: notmuch@notmuchmail.org
+References: <20091117190054.GU3165@dottiness.seas.harvard.edu>
+Date: Wed, 18 Nov 2009 01:02:38 +0600
+Message-ID: <87iqd9rn3l.fsf@vertex.dottedmag>
+MIME-Version: 1.0
+Subject: Re: [notmuch] Working with Maildir storage?
+Content-Type: multipart/mixed; boundary="===============1958295626=="
+
+--===============1958295626==
+Content-Type: multipart/signed; boundary="=-=-=";
+    micalg=pgp-sha1; protocol="application/pgp-signature"
+
+--=-=-=
+Content-Transfer-Encoding: quoted-printable
+
+Twas brillig at 14:00:54 17.11.2009 UTC-05 when lars@seas.harvard.edu did g=
+yre and gimble:
+
+--=-=-=
+Content-Type: application/pgp-signature
+
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.9 (GNU/Linux)
+
+iQIcBAEBAgAGBQJLAvNOAAoJEJ0g9lA+M4iIjLYQAKp0PXEgl3JMOEBisH52AsIK
+=/ksP
+-----END PGP SIGNATURE-----
+--=-=-=--
+
+--===============1958295626==
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Disposition: inline
+
+Testing!
+--===============1958295626==--
+`)
+	e, err := NewEmailFromReader(bytes.NewReader(raw))
+	if err != nil {
+		t.Fatalf("Error when parsing email %s", err.Error())
+	}
+}
+
 // *Since the mime library in use by ```email``` is now in the stdlib, this test is deprecated
 func Test_quotedPrintDecode(t *testing.T) {
 	text := []byte("Dear reader!\r\n\r\n" +