Module Name: src Committed By: christos Date: Fri Aug 28 14:26:50 UTC 2009
Modified Files: src/usr.bin/mail: mime_decode.c mime_detach.c Log Message: Don't barf on malformed mime messages (missing mime version). From Anon Ymous To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/usr.bin/mail/mime_decode.c cvs rdiff -u -r1.4 -r1.5 src/usr.bin/mail/mime_detach.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/mail/mime_decode.c diff -u src/usr.bin/mail/mime_decode.c:1.15 src/usr.bin/mail/mime_decode.c:1.16 --- src/usr.bin/mail/mime_decode.c:1.15 Fri Apr 10 09:08:25 2009 +++ src/usr.bin/mail/mime_decode.c Fri Aug 28 10:26:50 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: mime_decode.c,v 1.15 2009/04/10 13:08:25 christos Exp $ */ +/* $NetBSD: mime_decode.c,v 1.16 2009/08/28 14:26:50 christos Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ #include <sys/cdefs.h> #ifndef __lint__ -__RCSID("$NetBSD: mime_decode.c,v 1.15 2009/04/10 13:08:25 christos Exp $"); +__RCSID("$NetBSD: mime_decode.c,v 1.16 2009/08/28 14:26:50 christos Exp $"); #endif /* not __lint__ */ #include <assert.h> @@ -266,8 +266,15 @@ filename = savestr(filename); /* save it! */ } mip->mi_filename = filename; -} + /* + * XXX: If we have a "Content-Type" in the header, then assume + * we also have a "MIME-Version: 1.0". This fixes some broken + * MIME headers that I have seen occasionally. + */ + if (mip->mi_version == NULL && mip->mi_type != NULL) + mip->mi_version = MIME_VERSION; +} static struct message * salloc_message(int flag, long block, short offset) Index: src/usr.bin/mail/mime_detach.c diff -u src/usr.bin/mail/mime_detach.c:1.4 src/usr.bin/mail/mime_detach.c:1.5 --- src/usr.bin/mail/mime_detach.c:1.4 Fri Apr 10 09:08:25 2009 +++ src/usr.bin/mail/mime_detach.c Fri Aug 28 10:26:50 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: mime_detach.c,v 1.4 2009/04/10 13:08:25 christos Exp $ */ +/* $NetBSD: mime_detach.c,v 1.5 2009/08/28 14:26:50 christos Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ #include <sys/cdefs.h> #ifndef __lint__ -__RCSID("$NetBSD: mime_detach.c,v 1.4 2009/04/10 13:08:25 christos Exp $"); +__RCSID("$NetBSD: mime_detach.c,v 1.5 2009/08/28 14:26:50 christos Exp $"); #endif /* not __lint__ */ #include <assert.h> @@ -178,26 +178,36 @@ { char *pathname; char *prompt; + const char *partstr; + const char *subtype; + + /* + * XXX: If partstr == NULL, we probably shouldn't be detaching + * anything, but let's be liberal and try to do something with + * the block anyway. + */ + partstr = mip->mi_partstr && mip->mi_partstr[0] ? mip->mi_partstr : "0"; + subtype = mip->mi_subtype ? mip->mi_subtype : "unknown"; /* * Get the suggested target pathname. */ if (mip->mi_filename != NULL) - (void)sasprintf(&pathname, "%s/%s", mip->mi_detachdir, mip->mi_filename); + (void)sasprintf(&pathname, "%s/%s", mip->mi_detachdir, + mip->mi_filename); else { if (mip->mi_detachall == 0) return NULL; (void)sasprintf(&pathname, "%s/msg-%s.part-%s.%s", mip->mi_detachdir, mip->mi_msgstr, - mip->mi_partstr[0] ? mip->mi_partstr : "0", - mip->mi_subtype ? mip->mi_subtype : "unknown"); + partstr, subtype); } /* * Make up the prompt */ - (void)sasprintf(&prompt, "%-7s filename: ", mip->mi_partstr); + (void)sasprintf(&prompt, "%-7s filename: ", partstr); /* * The main loop. @@ -218,7 +228,7 @@ return NULL; continue; } - switch (detach_open_core(fname, mip->mi_partstr)) { + switch (detach_open_core(fname, partstr)) { case DETACH_OPEN_OK: return fname; case DETACH_NEXT: