]> diplodocus.org Git - nmh/blobdiff - uip/mhlistsbr.c
Alter HasSuffixC()'s char * to be const.
[nmh] / uip / mhlistsbr.c
index f5676a4990e2751fcc62e1ac2b327ba468e786a4..f5459cd400f942fb0c31a348dc9b35d542ec048c 100644 (file)
@@ -10,7 +10,6 @@
 
 #include <h/mh.h>
 #include <fcntl.h>
-#include <h/signals.h>
 #include <h/mts.h>
 #include <h/tws.h>
 #include <h/mime.h>
 #include <h/utils.h>
 
 /* mhmisc.c */
-int part_ok (CT, int);
+int part_ok (CT);
 int type_ok (CT, int);
 void flush_errors (void);
 
-/*
- * prototypes
- */
-void list_all_messages (CT *, int, int, int, int);
-int list_switch (CT, int, int, int, int);
-int list_content (CT, int, int, int, int);
-
 /*
  * static prototypes
  */
-static void list_single_message (CT, int, int, int);
+static void list_single_message (CT, int, int, int, int);
 static int list_debug (CT);
-static int list_multi (CT, int, int, int, int);
-static int list_partial (CT, int, int, int, int);
-static int list_external (CT, int, int, int, int);
-static int list_application (CT, int, int, int, int);
+static int list_multi (CT, int, int, int, int, int);
+static int list_partial (CT, int, int, int, int, int);
+static int list_external (CT, int, int, int, int, int);
+static int list_application (CT, int, int, int, int, int);
 static int list_encoding (CT);
 
 
@@ -47,12 +39,14 @@ static int list_encoding (CT);
 #define        LSTFMT1         "%4s %-5s %-24s %5s %s\n"
 #define        LSTFMT2a        "%4d "
 #define        LSTFMT2b        "%-5s %-24.24s "
+#define        LSTFMT2bv       "%-5s %-24s "
 #define        LSTFMT2c1       "%5lu"
 #define        LSTFMT2c2       "%4lu%c"
 #define        LSTFMT2c3       "huge "
 #define        LSTFMT2c4       "     "
 #define        LSTFMT2d1       " %.36s"
-#define        LSTFMT2d2       "\t     %-65.65s\n"
+#define        LSTFMT2d1v      " %s"
+#define        LSTFMT2d2       "\t     %-65s\n"
 
 
 /*
@@ -60,7 +54,8 @@ static int list_encoding (CT);
  */
 
 void
-list_all_messages (CT *cts, int headers, int realsize, int verbose, int debug)
+list_all_messages (CT *cts, int headers, int realsize, int verbose, int debug,
+                  int dispo)
 {
     CT ct, *ctp;
 
@@ -69,7 +64,7 @@ list_all_messages (CT *cts, int headers, int realsize, int verbose, int debug)
 
     for (ctp = cts; *ctp; ctp++) {
        ct = *ctp;
-       list_single_message (ct, realsize, verbose, debug);
+       list_single_message (ct, realsize, verbose, debug, dispo);
     }
 
     flush_errors ();
@@ -81,11 +76,11 @@ list_all_messages (CT *cts, int headers, int realsize, int verbose, int debug)
  */
 
 static void
-list_single_message (CT ct, int realsize, int verbose, int debug)
+list_single_message (CT ct, int realsize, int verbose, int debug, int dispo)
 {
     if (type_ok (ct, 1)) {
        umask (ct->c_umask);
-       list_switch (ct, 1, realsize, verbose, debug);
+       list_switch (ct, 1, realsize, verbose, debug, dispo);
        if (ct->c_fp) {
            fclose (ct->c_fp);
            ct->c_fp = NULL;
@@ -101,37 +96,39 @@ list_single_message (CT ct, int realsize, int verbose, int debug)
  */
 
 int
-list_switch (CT ct, int toplevel, int realsize, int verbose, int debug)
+list_switch (CT ct, int toplevel, int realsize, int verbose, int debug,
+            int dispo)
 {
     switch (ct->c_type) {
        case CT_MULTIPART:
-           return list_multi (ct, toplevel, realsize, verbose, debug);
+           return list_multi (ct, toplevel, realsize, verbose, debug, dispo);
 
        case CT_MESSAGE:
            switch (ct->c_subtype) {
                case MESSAGE_PARTIAL:
-                   return list_partial (ct, toplevel, realsize, verbose, debug);
+                   return list_partial (ct, toplevel, realsize, verbose,
+                                        debug, dispo);
 
                case MESSAGE_EXTERNAL:
-                   return list_external (ct, toplevel, realsize, verbose, debug);
+                   return list_external (ct, toplevel, realsize, verbose,
+                                         debug, dispo);
 
                case MESSAGE_RFC822:
                default:
-                   return list_content (ct, toplevel, realsize, verbose, debug);
+                   return list_content (ct, toplevel, realsize, verbose,
+                                        debug, dispo);
            }
 
        case CT_TEXT:
        case CT_AUDIO:
        case CT_IMAGE:
        case CT_VIDEO:
-           return list_content (ct, toplevel, realsize, verbose, debug);
+           return list_content (ct, toplevel, realsize, verbose, debug, dispo);
 
        case CT_APPLICATION:
-           return list_application (ct, toplevel, realsize, verbose, debug);
-
        default:
-           /* list_debug (ct); */
-           adios (NULL, "unknown content type %d", ct->c_type);
+           return list_application (ct, toplevel, realsize, verbose, debug,
+                                    dispo);
     }
 
     return 0;  /* NOT REACHED */
@@ -145,11 +142,13 @@ list_switch (CT ct, int toplevel, int realsize, int verbose, int debug)
  */
 
 int
-list_content (CT ct, int toplevel, int realsize, int verbose, int debug)
+list_content (CT ct, int toplevel, int realsize, int verbose, int debug,
+            int dispo)
 {
     unsigned long size;
     char *cp, buffer[BUFSIZ];
     CI ci = &ct->c_ctinfo;
+    PM pm;
 
     if (toplevel > 0)
        printf (LSTFMT2a, atoi (r1bindex (empty (ct->c_file), '/')));
@@ -158,7 +157,10 @@ list_content (CT ct, int toplevel, int realsize, int verbose, int debug)
 
     snprintf (buffer, sizeof(buffer), "%s/%s", empty (ci->ci_type),
                empty (ci->ci_subtype));
-    printf (LSTFMT2b, empty (ct->c_partno), buffer);
+    if (verbose)
+       printf (LSTFMT2bv, empty (ct->c_partno), buffer);
+    else
+       printf (LSTFMT2b, empty (ct->c_partno), buffer);
 
     if (ct->c_cesizefnx && realsize)
        size = (*ct->c_cesizefnx) (ct);
@@ -166,7 +168,7 @@ list_content (CT ct, int toplevel, int realsize, int verbose, int debug)
        size = ct->c_end - ct->c_begin;
 
     /* find correct scale for size (Kilo/Mega/Giga/Tera) */
-    for (cp = " KMGT"; size > 9999; size >>= 10)
+    for (cp = " KMGT"; size > 9999; size /= 1000)
        if (!*++cp)
            break;
 
@@ -192,15 +194,17 @@ list_content (CT ct, int toplevel, int realsize, int verbose, int debug)
        char *dp;
 
        dp = cpytrim (ct->c_descr);
-       printf (LSTFMT2d1, dp);
+       if (verbose)
+           printf (LSTFMT2d1v, dp);
+       else
+           printf (LSTFMT2d1, dp);
        free (dp);
     }
 
-    printf ("\n");
+    putchar('\n');
 
     if (verbose) {
        CI ci = &ct->c_ctinfo;
-       PM pm;
 
        for (pm = ci->ci_first_pm; pm; pm = pm->pm_next) {
            printf ("\t     %s=\"%s\"\n", pm->pm_name,
@@ -221,6 +225,17 @@ list_content (CT ct, int toplevel, int realsize, int verbose, int debug)
        }
     }
 
+    if (dispo && ct->c_dispo_type) {
+       printf ("\t     disposition \"%s\"\n", ct->c_dispo_type);
+
+       if (verbose) {
+           for (pm = ct->c_dispo_first; pm; pm = pm->pm_next) {
+               printf ("\t       %s=\"%s\"\n", pm->pm_name,
+                       get_param_value(pm, '?'));
+           }
+       }
+    }
+
     if (debug)
        list_debug (ct);
 
@@ -286,6 +301,16 @@ list_debug (CT ct)
     if (ct->c_descr)
        fprintf (stderr, "  %s:%s", DESCR_FIELD, ct->c_descr);
 
+    /* print Content-Disposition */
+    if (ct->c_dispo)
+       fprintf (stderr, "  %s:%s", DISPO_FIELD, ct->c_dispo);
+
+    fprintf(stderr, "    disposition \"%s\"\n", empty (ct->c_dispo_type));
+    fprintf(stderr, "    disposition parameters\n");
+    for (pm = ct->c_dispo_first; pm; pm = pm->pm_next)
+       fprintf (stderr, "      %s=\"%s\"\n", pm->pm_name,
+                get_param_value(pm, '?'));
+
     fprintf (stderr, "    read fp 0x%x file \"%s\" begin %ld end %ld\n",
             (unsigned int)(unsigned long) ct->c_fp, empty (ct->c_file),
             ct->c_begin, ct->c_end);
@@ -304,20 +329,21 @@ list_debug (CT ct)
  */
 
 static int
-list_multi (CT ct, int toplevel, int realsize, int verbose, int debug)
+list_multi (CT ct, int toplevel, int realsize, int verbose, int debug,
+           int dispo)
 {
     struct multipart *m = (struct multipart *) ct->c_ctparams;
     struct part *part;
 
     /* list the content for toplevel of this multipart */
-    list_content (ct, toplevel, realsize, verbose, debug);
+    list_content (ct, toplevel, realsize, verbose, debug, dispo);
 
     /* now list for all the subparts */
     for (part = m->mp_parts; part; part = part->mp_next) {
        CT p = part->mp_part;
 
-       if (part_ok (p, 1) && type_ok (p, 1))
-           list_switch (p, 0, realsize, verbose, debug);
+       if (part_ok (p) && type_ok (p, 1))
+           list_switch (p, 0, realsize, verbose, debug, dispo);
     }
 
     return OK;
@@ -329,11 +355,12 @@ list_multi (CT ct, int toplevel, int realsize, int verbose, int debug)
  */
 
 static int
-list_partial (CT ct, int toplevel, int realsize, int verbose, int debug)
+list_partial (CT ct, int toplevel, int realsize, int verbose, int debug,
+             int dispo)
 {
     struct partial *p = (struct partial *) ct->c_ctparams;
 
-    list_content (ct, toplevel, realsize, verbose, debug);
+    list_content (ct, toplevel, realsize, verbose, debug, dispo);
     if (verbose) {
        printf ("\t     [message %s, part %d", p->pm_partid, p->pm_partno);
        if (p->pm_maxno)
@@ -350,7 +377,8 @@ list_partial (CT ct, int toplevel, int realsize, int verbose, int debug)
  */
 
 static int
-list_external (CT ct, int toplevel, int realsize, int verbose, int debug)
+list_external (CT ct, int toplevel, int realsize, int verbose, int debug,
+              int dispo)
 {
     struct exbody *e = (struct exbody *) ct->c_ctparams;
 
@@ -358,7 +386,7 @@ list_external (CT ct, int toplevel, int realsize, int verbose, int debug)
      * First list the information for the
      * message/external content itself.
      */
-    list_content (ct, toplevel, realsize, verbose, debug);
+    list_content (ct, toplevel, realsize, verbose, debug, dispo);
 
     if (verbose) {
        if (e->eb_name)
@@ -371,6 +399,8 @@ list_external (CT ct, int toplevel, int realsize, int verbose, int debug)
            printf ("\t     server=\"%s\"\n", e->eb_server);
        if (e->eb_subject)
            printf ("\t     subject=\"%s\"\n", e->eb_subject);
+       if (e->eb_url)
+           printf ("\t     url=\"%s\"\n", e->eb_url);
 
        /* This must be defined */
        printf     ("\t     access-type=\"%s\"\n", e->eb_access);
@@ -382,13 +412,14 @@ list_external (CT ct, int toplevel, int realsize, int verbose, int debug)
 
        if (e->eb_flags == NOTOK)
            printf ("\t     [service unavailable]\n");
+
     }
 
     /*
      * Now list the information for the external content
      * to which this content points.
      */
-    list_content (e->eb_content, 0, realsize, verbose, debug);
+    list_content (e->eb_content, 0, realsize, verbose, debug, dispo);
 
     return OK;
 }
@@ -402,9 +433,10 @@ list_external (CT ct, int toplevel, int realsize, int verbose, int debug)
  */
 
 static int
-list_application (CT ct, int toplevel, int realsize, int verbose, int debug)
+list_application (CT ct, int toplevel, int realsize, int verbose, int debug,
+                 int dispo)
 {
-    list_content (ct, toplevel, realsize, verbose, debug);
+    list_content (ct, toplevel, realsize, verbose, debug, dispo);
 
     return OK;
 }