Print information about the external body parts.
Showing
1 changed file
with
135 additions
and
2 deletions
... | @@ -874,6 +874,121 @@ mhn_store_command (message_t msg, msg_part_t part, char *name) | ... | @@ -874,6 +874,121 @@ mhn_store_command (message_t msg, msg_part_t part, char *name) |
874 | } | 874 | } |
875 | 875 | ||
876 | 876 | ||
877 | /* ************************* Auxiliary functions ************************** */ | ||
878 | |||
879 | int | ||
880 | _message_is_external_body (message_t msg, char ***env) | ||
881 | { | ||
882 | int rc; | ||
883 | header_t hdr; | ||
884 | char *typestr, *argstr, *type, *subtype; | ||
885 | |||
886 | if (message_get_header (msg, &hdr)) | ||
887 | return 0; | ||
888 | _get_content_type (hdr, &typestr, &argstr); | ||
889 | split_content (typestr, &type, &subtype); | ||
890 | rc = strcmp (subtype, "external-body") == 0; | ||
891 | if (rc && env) | ||
892 | { | ||
893 | int argc; | ||
894 | char **argv; | ||
895 | if (argcv_get (argstr, ";", NULL, &argc, &argv) == 0) | ||
896 | { | ||
897 | int i, j; | ||
898 | |||
899 | for (i = j = 0; i < argc; i++) | ||
900 | { | ||
901 | if (argv[i][0] != ';') | ||
902 | argv[j++] = argv[i]; | ||
903 | } | ||
904 | argv[j] = NULL; | ||
905 | *env = argv; | ||
906 | } | ||
907 | else | ||
908 | *env = NULL; | ||
909 | } | ||
910 | |||
911 | free (typestr); | ||
912 | free (type); | ||
913 | free (subtype); | ||
914 | return rc; | ||
915 | } | ||
916 | |||
917 | char * | ||
918 | _get_env (char **env, char *name) | ||
919 | { | ||
920 | int nlen = strlen (name); | ||
921 | for (; *env; env++) | ||
922 | { | ||
923 | int len = strlen (*env); | ||
924 | if (nlen < len | ||
925 | && (*env)[len+1] == '=' | ||
926 | && strncasecmp (*env, name, nlen) == 0) | ||
927 | return *env + len + 1; | ||
928 | } | ||
929 | return NULL; | ||
930 | } | ||
931 | |||
932 | void | ||
933 | _free_env (char **env) | ||
934 | { | ||
935 | char **p; | ||
936 | |||
937 | for (p = env; *p; p++) | ||
938 | free (*p); | ||
939 | free (env); | ||
940 | } | ||
941 | |||
942 | int | ||
943 | get_extbody_params (message_t msg, char **content, char **descr) | ||
944 | { | ||
945 | int rc = 0; | ||
946 | body_t body = NULL; | ||
947 | stream_t stream = NULL; | ||
948 | char buf[128]; | ||
949 | size_t n; | ||
950 | |||
951 | message_get_body (msg, &body); | ||
952 | body_get_stream (body, &stream); | ||
953 | stream_seek (stream, 0, SEEK_SET); | ||
954 | |||
955 | while (rc == 0 | ||
956 | && stream_sequential_readline (stream, buf, sizeof buf, &n) == 0 | ||
957 | && n > 0) | ||
958 | { | ||
959 | char *p; | ||
960 | int len = strlen (buf); | ||
961 | |||
962 | if (len > 0 && buf[len-1] == '\n') | ||
963 | buf[len-1] = 0; | ||
964 | |||
965 | if (descr | ||
966 | && strncasecmp (buf, MU_HEADER_CONTENT_DESCRIPTION ":", | ||
967 | sizeof (MU_HEADER_CONTENT_DESCRIPTION)) == 0) | ||
968 | { | ||
969 | for (p = buf + sizeof (MU_HEADER_CONTENT_DESCRIPTION); | ||
970 | *p && isspace (*p); p++) | ||
971 | ; | ||
972 | *descr = strdup (p); | ||
973 | } | ||
974 | else if (content | ||
975 | && strncasecmp (buf, MU_HEADER_CONTENT_TYPE ":", | ||
976 | sizeof (MU_HEADER_CONTENT_TYPE)) == 0) | ||
977 | { | ||
978 | char *q; | ||
979 | for (p = buf + sizeof (MU_HEADER_CONTENT_TYPE); | ||
980 | *p && isspace (*p); p++) | ||
981 | ; | ||
982 | q = strchr (p, ';'); | ||
983 | if (q) | ||
984 | *q = 0; | ||
985 | *content = strdup (p); | ||
986 | } | ||
987 | } | ||
988 | return 0; | ||
989 | } | ||
990 | |||
991 | |||
877 | /* ************************** Message iterators *************************** */ | 992 | /* ************************** Message iterators *************************** */ |
878 | 993 | ||
879 | 994 | ||
... | @@ -1048,6 +1163,24 @@ list_handler (message_t msg, msg_part_t part, char *type, char *encoding, | ... | @@ -1048,6 +1163,24 @@ list_handler (message_t msg, msg_part_t part, char *type, char *encoding, |
1048 | } | 1163 | } |
1049 | 1164 | ||
1050 | printf ("\n"); | 1165 | printf ("\n"); |
1166 | |||
1167 | if (_message_is_external_body (msg, NULL)) | ||
1168 | { | ||
1169 | char *content_type = NULL; | ||
1170 | char *content_descr = NULL; | ||
1171 | |||
1172 | get_extbody_params (msg, &content_type, &content_descr); | ||
1173 | |||
1174 | printf (" "); | ||
1175 | printf ("%-25s", content_type ? content_type : ""); | ||
1176 | if (content_descr) | ||
1177 | printf (" %s", content_descr); | ||
1178 | printf ("\n"); | ||
1179 | |||
1180 | free (content_type); | ||
1181 | free (content_descr); | ||
1182 | } | ||
1183 | |||
1051 | return 0; | 1184 | return 0; |
1052 | } | 1185 | } |
1053 | 1186 | ||
... | @@ -1110,7 +1243,7 @@ show_internal (message_t msg, msg_part_t part, char *encoding, stream_t out) | ... | @@ -1110,7 +1243,7 @@ show_internal (message_t msg, msg_part_t part, char *encoding, stream_t out) |
1110 | int rc; | 1243 | int rc; |
1111 | body_t body = NULL; | 1244 | body_t body = NULL; |
1112 | stream_t dstr, bstr; | 1245 | stream_t dstr, bstr; |
1113 | 1246 | ||
1114 | if ((rc = message_get_body (msg, &body))) | 1247 | if ((rc = message_get_body (msg, &body))) |
1115 | { | 1248 | { |
1116 | mh_error (_("%lu: can't get message body: %s"), | 1249 | mh_error (_("%lu: can't get message body: %s"), |
... | @@ -1128,7 +1261,7 @@ show_internal (message_t msg, msg_part_t part, char *encoding, stream_t out) | ... | @@ -1128,7 +1261,7 @@ show_internal (message_t msg, msg_part_t part, char *encoding, stream_t out) |
1128 | stream_destroy (&dstr, stream_get_owner (dstr)); | 1261 | stream_destroy (&dstr, stream_get_owner (dstr)); |
1129 | return 0; | 1262 | return 0; |
1130 | } | 1263 | } |
1131 | 1264 | ||
1132 | int | 1265 | int |
1133 | mhn_exec (stream_t *str, char *cmd, int flags) | 1266 | mhn_exec (stream_t *str, char *cmd, int flags) |
1134 | { | 1267 | { | ... | ... |
-
Please register or sign in to post a comment