Split off mail_copy0. It is shared between mail_copy
and mail_save. Implemented Copy command. Use mailbox_open_default() instead of mailbox_open(). Fixed possible memory leaks.
Showing
1 changed file
with
31 additions
and
20 deletions
... | @@ -24,11 +24,11 @@ | ... | @@ -24,11 +24,11 @@ |
24 | */ | 24 | */ |
25 | 25 | ||
26 | /* | 26 | /* |
27 | * NOTE: outfolder variable | 27 | * Shared between mail_copy() and mail_save(). |
28 | */ | 28 | */ |
29 | 29 | ||
30 | int | 30 | int |
31 | mail_copy (int argc, char **argv) | 31 | mail_copy0 (int argc, char **argv, int mark) |
32 | { | 32 | { |
33 | message_t msg; | 33 | message_t msg; |
34 | mailbox_t mbx; | 34 | mailbox_t mbx; |
... | @@ -40,41 +40,52 @@ mail_copy (int argc, char **argv) | ... | @@ -40,41 +40,52 @@ mail_copy (int argc, char **argv) |
40 | if (isupper (argv[0][0])) | 40 | if (isupper (argv[0][0])) |
41 | sender = 1; | 41 | sender = 1; |
42 | else if (argc >= 2) | 42 | else if (argc >= 2) |
43 | filename = argv[--argc]; | 43 | filename = strdup(argv[--argc]); |
44 | else | 44 | else |
45 | { | 45 | filename = strdup("mbox"); |
46 | filename = strdup ("mbox"); | ||
47 | } | ||
48 | 46 | ||
49 | num = util_expand_msglist (argc, argv, &msglist); | 47 | num = util_expand_msglist (argc, argv, &msglist); |
50 | |||
51 | if (sender) | 48 | if (sender) |
52 | { | 49 | { |
53 | mailbox_get_message (mbox, num > 0 ? msglist[0] : cursor, 0); | 50 | filename = util_get_sender(msglist[0], 1); |
54 | /* get from */ | 51 | if (!filename) |
55 | /* filename = login name part */ | 52 | { |
53 | free (msglist); | ||
54 | return 1; | ||
55 | } | ||
56 | } | 56 | } |
57 | 57 | ||
58 | mailbox_create (&mbx, filename); | 58 | if (mailbox_create_default (&mbx, filename) |
59 | mailbox_open (mbx, MU_STREAM_WRITE | MU_STREAM_CREAT); | 59 | || mailbox_open (mbx, MU_STREAM_WRITE | MU_STREAM_CREAT)) |
60 | |||
61 | if (num > 0) | ||
62 | { | 60 | { |
63 | for (i=0; i < num; i++) | 61 | fprintf (ofile, "can't create mailbox %s\n", filename); |
62 | free (filename); | ||
63 | free (msglist); | ||
64 | return 1; | ||
65 | } | ||
66 | |||
67 | fprintf (ofile, "%s\n", filename); | ||
68 | |||
69 | for (i = 0; i < num; i++) | ||
64 | { | 70 | { |
65 | mailbox_get_message (mbox, msglist[i], &msg); | 71 | mailbox_get_message (mbox, msglist[i], &msg); |
66 | mailbox_append_message (mbx, msg); | 72 | mailbox_append_message (mbx, msg); |
67 | } | 73 | if (mark) |
68 | } | ||
69 | else | ||
70 | { | 74 | { |
71 | mailbox_get_message (mbox, cursor, &msg); | 75 | /*FIXME: mark as saved */; |
72 | mailbox_append_message (mbx, msg); | 76 | } |
73 | } | 77 | } |
74 | 78 | ||
75 | mailbox_close (mbx); | 79 | mailbox_close (mbx); |
76 | mailbox_destroy (&mbx); | 80 | mailbox_destroy (&mbx); |
77 | 81 | ||
82 | free (filename); | ||
78 | free (msglist); | 83 | free (msglist); |
79 | return 0; | 84 | return 0; |
80 | } | 85 | } |
86 | |||
87 | int | ||
88 | mail_copy (int argc, char **argv) | ||
89 | { | ||
90 | return mail_copy0 (argc, argv, 0); | ||
91 | } | ... | ... |
-
Please register or sign in to post a comment