1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2009-2021 Free Software Foundation, Inc.
3
4 GNU Mailutils is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 GNU Mailutils is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16
17 #include "mail.h"
18
19 static int
show_part(struct mime_descend_closure * closure,void * data)20 show_part (struct mime_descend_closure *closure, void *data)
21 {
22 char *msp;
23 size_t size;
24
25 msp = msgset_str (closure->msgset);
26 mu_printf ("%-16s %-25s", msp, closure->type);
27 free (msp);
28
29 mu_message_size (closure->message, &size);
30 if (size < 1024)
31 mu_printf (" %4lu", (unsigned long) size);
32 else if (size < 1024*1024)
33 mu_printf ("%4luK", (unsigned long) size / 1024);
34 else
35 mu_printf ("%4luM", (unsigned long) size / 1024 / 1024);
36 mu_printf ("\n");
37 return 0;
38 }
39
40 static int
show_struct(msgset_t * msgset,mu_message_t msg,void * data)41 show_struct (msgset_t *msgset, mu_message_t msg, void *data)
42 {
43 struct mime_descend_closure mclos;
44
45 mclos.hints = 0;
46 mclos.msgset = msgset;
47 mclos.message = msg;
48 mclos.type = NULL;
49 mclos.encoding = NULL;
50 mclos.parent = NULL;
51
52 mime_descend (&mclos, show_part, NULL);
53
54 /* Mark enclosing message as read */
55 if (mu_mailbox_get_message (mbox, msgset_msgno (msgset), &msg) == 0)
56 util_mark_read (msg);
57
58 return 0;
59 }
60
61 int
mail_struct(int argc,char ** argv)62 mail_struct (int argc, char **argv)
63 {
64 return util_foreach_msg (argc, argv, MSG_NODELETED|MSG_SILENT,
65 show_struct, NULL);
66 }
67