Here is a patch that implements the solution I discussed with James
Baker for the automatic extraction of all MIME parts of a message with
"reformime -xPREFIX".

This patch creates one more flag for reformime: "-u" so instead of
"reformime -xPREFIX" I suggest "reformime -xPREFIX -u".

The -u flag will include an 8 hexa digits counter between PREFIX and the
original filename.

Does anybody cares to test it?

BTW: if PREFIX is a directory, please end it with '/'. As far as I
understand, this observation applies to reformime with or without this
patch.


Rodrigo Severo



*** ../courier.original/courier-0.42.2/rfc2045/reformime.c 2003-03-06 21:47:08.000000000 -0300 --- ./rfc2045/reformime.c 2003-06-23 09:49:11.000000000 -0300 *************** *** 97,102 **** --- 97,103 ---- fprintf(stderr, " -h \"header\" - decode RFC 2047-encoded header.\n"); fprintf(stderr, " -o \"header\" - encode unstructured header using RFC 2047.\n"); fprintf(stderr, " -O \"header\" - encode address list header using RFC 2047.\n"); + fprintf(stderr, " -u - include a unique value for each MIME section (usefull with -xPREFIX and without -s).\n");

        exit(1);
  }
***************
*** 620,626 ****
  static void extract_section(struct rfc2045 *top_rfcp, const char
*mimesection,
        const char *extract_filename, int argc, char **argv,
        void    (*extract_func)(struct rfc2045 *, const char *,
!               int, char **))
  {
        if (mimesection)
        {
--- 621,627 ----
  static void extract_section(struct rfc2045 *top_rfcp, const char
*mimesection,
        const char *extract_filename, int argc, char **argv,
        void    (*extract_func)(struct rfc2045 *, const char *,
!               int, char **), const int unique)
  {
        if (mimesection)
        {
***************
*** 640,649 ****

        if (top_rfcp->firstpart)
        {
!               for (top_rfcp=top_rfcp->firstpart; top_rfcp;
!                       top_rfcp=top_rfcp->next)
!                       extract_section(top_rfcp, mimesection,
!                               extract_filename, argc, argv, extract_func);
                return;
        }

--- 641,681 ----

        if (top_rfcp->firstpart)
        {
!               if (unique)
!               {
!                       char *unique_filename;
!                       unsigned long int unique_filename_size;
!                       unsigned long int attachment_counter=0;
!
!                       unique_filename_size=strlen(extract_filename)+10; // The 10 is 
8
hexa digits + 1 for a final hyphen + 1 for the final \0
!                       unique_filename=malloc(unique_filename_size);
!                       if (!unique_filename)                           
!       {
!                               perror("malloc");
!                               exit(1);
!                       }
!                       for (top_rfcp=top_rfcp->firstpart; top_rfcp;
!                               top_rfcp=top_rfcp->next)
!                       {
!                               if (snprintf(unique_filename, unique_filename_size,
!                                       "%s%.8lx-", extract_filename, attachment_counter) 
>=
unique_filename_size)
!                               {
!                                       perror("snprintf");
!                                       exit(1);
!                               }
!                               extract_section(top_rfcp, mimesection,
!                                       unique_filename, argc, argv, extract_func, 0);
!                               attachment_counter++;
!                       }
!                       free(unique_filename);
!               }
!               else
!               {
!                       for (top_rfcp=top_rfcp->firstpart; top_rfcp;
!                               top_rfcp=top_rfcp->next)
!                               extract_section(top_rfcp, mimesection,
!                                       extract_filename, argc, argv, extract_func, 0);
!               }
                return;
        }

***************
*** 918,923 ****
--- 950,956 ----
  void  (*do_extract)(struct rfc2045 *, const char *, int, char **)=0;
  const char *extract_filename=0;
  int rc=0;
+ int unique=0;

  #if HAVE_SETLOCALE
        setlocale(LC_ALL, "C");
***************
*** 1011,1016 ****
--- 1044,1052 ----
                        }
                        doencodemimehdr=1;
                        break;
+               case 'u':
+                       unique=1;
+                       break;

                default:
                        usage();
***************
*** 1068,1074 ****
                print_info(p, mimesection);
                if (do_extract)
                        extract_section(p, mimesection, extract_filename,
!                                       argc-argn, argv+argn, do_extract);
        }
        else if (dodecode)
                print_decode(p, mimesection);
--- 1104,1110 ----
                print_info(p, mimesection);
                if (do_extract)
                        extract_section(p, mimesection, extract_filename,
!                                       argc-argn, argv+argn, do_extract, 0);
        }
        else if (dodecode)
                print_decode(p, mimesection);
***************
*** 1078,1084 ****
                dsn(p, dodsn == 2);
        else if (do_extract)
                extract_section(p, mimesection, extract_filename,
!                       argc-argn, argv+argn, do_extract);
        else if (dovalidate)
        {
                rc=1;
--- 1114,1120 ----
                dsn(p, dodsn == 2);
        else if (do_extract)
                extract_section(p, mimesection, extract_filename,
!                       argc-argn, argv+argn, do_extract, unique);
        else if (dovalidate)
        {
                rc=1;


-- ---------------------------------------------------- Rodrigo Severo Fábrica de Idéias Fone: +55(61)321 1357 Fax: +55(61)223 1712 SBS - Quadra 2 - Ed. Empire Center - Sala 1301 Brasília/DF - Brasil CEP: 70.070-904 ----------------------------------------------------



-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
courier-users mailing list
[EMAIL PROTECTED]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users

Reply via email to