<<< Date Index >>>     <<< Thread Index >>>

application/octet-stream everywhere



Hi,

last few days I'm getting mails containing application/octet-stream
attachments, even that they could have valid mime types. Up till now I
solved this by having octet-stream definition in ~/.mimetypes, and
having external script deciding on how to open file according to the
extension.

Mutt has also second mime database called .mime.types, which is used to
set proper type while sending files. What about using them together ? I
did very quick change to rfc1524.c and it seems to be working quite
fine. It's very rough though.

Things to do:
 - decide if it's good solution
 - cleanup (remove comments)
 - snprintf (type, sizeof(type), "%s/%s", ... is taken from other
source. Would be good to make it function and just call it from here.
 - type[LONG_STRING] probably too big, dunno what is max mime-type size
 - bzero(&tmp, sizeof(BODY)) ...
 - make mutt config option to disable/enable this feature ?
 - make auto_view also use .mime.types ?


Generally, what do you think ?

Thanks

-- 
        Vlad

diff -r d13f7abeb868 rfc1524.c
--- a/rfc1524.c Sun Jun 24 19:42:38 2007 +0200
+++ b/rfc1524.c Sun Jun 24 20:30:35 2007 +0200
@@ -32,6 +32,7 @@

 #include "mutt.h"
 #include "rfc1524.h"
+#include "mime.h"

 #include <string.h>
 #include <stdlib.h>
@@ -377,12 +378,52 @@ void rfc1524_free_entry(rfc1524_entry **
  * in *entry, and returns 1.  On failure (not found), returns 0.
  * If entry == NULL just return 1 if the given type is found.
  */
-int rfc1524_mailcap_lookup (BODY *a, char *type, rfc1524_entry *entry, int opt)
+int rfc1524_mailcap_lookup (BODY *a, char *t, rfc1524_entry *entry, int opt)
 {
   char path[_POSIX_PATH_MAX];
   int x;
   int found = FALSE;
   char *curr = MailcapPath;
+  char type[LONG_STRING];
+
+  strcpy(type, t);
+/*--------------------------------------------------
+*   printf ("type %s\n", type);
+*   if (a->filename == NULL)
+*   {
+*        printf ("File is null !\n");
+*   }
+*   else
+*   {
+*        printf ("File: %s\n", a->filename);
+*   }
+*--------------------------------------------------*/
+  if (a->filename!=NULL && !mutt_strncmp(type, "application/octet-stream", 
sizeof(type)))
+  {
+/*--------------------------------------------------
+*     printf ("Application/octet-stream, file: %s\n", a->filename);
+*--------------------------------------------------*/
+    BODY tmp;
+    int n;
+
+    tmp.xtype='\0';
+    tmp.subtype='\0';
+    if ((n = mutt_lookup_mime_type (&tmp, a->filename)) != TYPEOTHER) {
+      snprintf (type, sizeof(type), "%s/%s",
+                n == TYPEAUDIO ? "audio" :
+                n == TYPEAPPLICATION ? "application" :
+                n == TYPEIMAGE ? "image" :
+                n == TYPEMESSAGE ? "message" :
+                n == TYPEMODEL ? "model" :
+                n == TYPEMULTIPART ? "multipart" :
+                n == TYPETEXT ? "text" :
+                n == TYPEVIDEO ? "video" : "other",
+                tmp.subtype);
+    }
+/*--------------------------------------------------
+*     printf ("(2)Mime type changed to %s\n", type);
+*--------------------------------------------------*/
+  }

   /* rfc1524 specifies that a path of mailcap files should be searched.
    * joy.  They say