(mh_draft_message): New function
Showing
1 changed file
with
63 additions
and
0 deletions
... | @@ -20,6 +20,7 @@ | ... | @@ -20,6 +20,7 @@ |
20 | /* Initialize MH applications. */ | 20 | /* Initialize MH applications. */ |
21 | 21 | ||
22 | #include <mh.h> | 22 | #include <mh.h> |
23 | #include <mailutils/url.h> | ||
23 | #include <pwd.h> | 24 | #include <pwd.h> |
24 | #include <sys/types.h> | 25 | #include <sys/types.h> |
25 | #include <sys/stat.h> | 26 | #include <sys/stat.h> |
... | @@ -917,3 +918,65 @@ mh_expand_aliases (mu_message_t msg, | ... | @@ -917,3 +918,65 @@ mh_expand_aliases (mu_message_t msg, |
917 | } | 918 | } |
918 | } | 919 | } |
919 | } | 920 | } |
921 | |||
922 | int | ||
923 | mh_draft_message (const char *name, const char *msgspec, char **pname) | ||
924 | { | ||
925 | mu_url_t url; | ||
926 | size_t uid; | ||
927 | int rc; | ||
928 | const char *urlstr; | ||
929 | mu_mailbox_t mbox; | ||
930 | |||
931 | mbox = mh_open_folder (name, 0); | ||
932 | if (!mbox) | ||
933 | return 1; | ||
934 | |||
935 | mu_mailbox_get_url (mbox, &url); | ||
936 | urlstr = mu_url_to_string (url); | ||
937 | |||
938 | if (strcmp (msgspec, "new") == 0) | ||
939 | { | ||
940 | rc = mu_mailbox_uidnext (mbox, &uid); | ||
941 | if (rc) | ||
942 | mu_error (_("Cannot obtain sequence number for the new message"), | ||
943 | mu_strerror (rc)); | ||
944 | } | ||
945 | else | ||
946 | { | ||
947 | char *argv[2]; | ||
948 | mh_msgset_t msgset; | ||
949 | |||
950 | argv[0] = (char*) msgspec; | ||
951 | argv[1] = NULL; | ||
952 | rc = mh_msgset_parse (mbox, &msgset, 1, argv, "cur"); | ||
953 | if (rc) | ||
954 | mu_error (_("Invalid message number: %s"), msgspec); | ||
955 | else if (msgset.count > 1) | ||
956 | mu_error (_("only one message at a time!")); | ||
957 | else | ||
958 | uid = msgset.list[0]; | ||
959 | |||
960 | mh_msgset_free (&msgset); | ||
961 | } | ||
962 | |||
963 | if (rc == 0) | ||
964 | { | ||
965 | const char *dir; | ||
966 | const char *msg; | ||
967 | size_t len; | ||
968 | |||
969 | dir = urlstr + 3; /* FIXME */ | ||
970 | |||
971 | msg = mu_umaxtostr (0, uid); | ||
972 | len = strlen (dir) + 1 + strlen (msg) + 1; | ||
973 | *pname = xmalloc (len); | ||
974 | strcpy (*pname, dir); | ||
975 | strcat (*pname, "/"); | ||
976 | strcat (*pname, msg); | ||
977 | } | ||
978 | mu_mailbox_close (mbox); | ||
979 | mu_mailbox_destroy (&mbox); | ||
980 | return rc; | ||
981 | } | ||
982 | ... | ... |
-
Please register or sign in to post a comment