Implemented #forw directive.
Showing
1 changed file
with
136 additions
and
5 deletions
... | @@ -1740,9 +1740,116 @@ edit_extern (char *cmd, struct compose_env *env, message_t *msg, int level) | ... | @@ -1740,9 +1740,116 @@ edit_extern (char *cmd, struct compose_env *env, message_t *msg, int level) |
1740 | } | 1740 | } |
1741 | 1741 | ||
1742 | int | 1742 | int |
1743 | edit_forw (char *cmd, struct compose_env *env, message_t *msg, int level) | 1743 | edit_forw (char *cmd, struct compose_env *env, message_t *pmsg, int level) |
1744 | { | 1744 | { |
1745 | return 0; | 1745 | char *sp, *id = NULL, *descr = NULL; |
1746 | int stop = 0, status = 0; | ||
1747 | int i, argc; | ||
1748 | char **argv; | ||
1749 | header_t hdr; | ||
1750 | mime_t mime; | ||
1751 | message_t msg; | ||
1752 | char *val, *newval; | ||
1753 | |||
1754 | skipws (cmd); | ||
1755 | while (stop == 0 && status == 0 && *cmd) | ||
1756 | { | ||
1757 | switch (*cmd++) | ||
1758 | { | ||
1759 | case '[': | ||
1760 | if (descr) | ||
1761 | { | ||
1762 | mh_error (_("%s:%lu: description redefined"), | ||
1763 | input_file, | ||
1764 | (unsigned long) mhn_error_loc (env)); | ||
1765 | status = 1; | ||
1766 | break; | ||
1767 | } | ||
1768 | status = parse_brace (&descr, &cmd, ']', env); | ||
1769 | break; | ||
1770 | |||
1771 | case '<': | ||
1772 | if (id) | ||
1773 | { | ||
1774 | mh_error (_("%s:%lu: content id redefined"), | ||
1775 | input_file, | ||
1776 | (unsigned long) mhn_error_loc (env)); | ||
1777 | status = 1; | ||
1778 | break; | ||
1779 | } | ||
1780 | status = parse_brace (&id, &cmd, '>', env); | ||
1781 | break; | ||
1782 | |||
1783 | default: | ||
1784 | cmd--; | ||
1785 | stop = 1; | ||
1786 | break; | ||
1787 | } | ||
1788 | skipws (cmd); | ||
1789 | } | ||
1790 | if (status) | ||
1791 | return status; | ||
1792 | |||
1793 | if (argcv_get (cmd, "\n", NULL, &argc, &argv)) | ||
1794 | { | ||
1795 | mh_error (_("%s:%lu: syntax error"), | ||
1796 | input_file, | ||
1797 | (unsigned long) mhn_error_loc (env)); | ||
1798 | return 1; | ||
1799 | } | ||
1800 | |||
1801 | mime_create (&mime, NULL, 0); | ||
1802 | |||
1803 | mbox = mh_open_folder (argv[0], 0); | ||
1804 | for (i = 1; i < argc; i++) | ||
1805 | { | ||
1806 | message_t input_msg; | ||
1807 | if (mh_get_message (mbox, i, &input_msg) == 0) | ||
1808 | { | ||
1809 | mh_error (_("%s:%lu: no such message: %lu"), | ||
1810 | input_file, | ||
1811 | (unsigned long) mhn_error_loc (env), | ||
1812 | (unsigned long)i); | ||
1813 | return 1; | ||
1814 | } | ||
1815 | |||
1816 | if ((status = message_create_copy (&msg, input_msg))) | ||
1817 | break; | ||
1818 | mime_add_part (mime, msg); | ||
1819 | } | ||
1820 | argcv_free (argc, argv); | ||
1821 | |||
1822 | if (*pmsg) | ||
1823 | { | ||
1824 | message_unref (*pmsg); | ||
1825 | *pmsg = NULL; | ||
1826 | } | ||
1827 | |||
1828 | mime_get_message (mime, &msg); | ||
1829 | message_get_header (msg, &hdr); | ||
1830 | header_aget_value (hdr, MU_HEADER_CONTENT_TYPE, &val); | ||
1831 | sp = strchr (val, ';'); | ||
1832 | if (!sp) | ||
1833 | abort (); | ||
1834 | asprintf (&newval, "multipart/digest%s", sp); | ||
1835 | header_set_value (hdr, MU_HEADER_CONTENT_TYPE, newval, 1); | ||
1836 | free (val); | ||
1837 | free (newval); | ||
1838 | |||
1839 | if (!id) | ||
1840 | id = mh_create_message_id (env->subpart); | ||
1841 | |||
1842 | header_set_value (hdr, MU_HEADER_CONTENT_ID, id, 1); | ||
1843 | free (id); | ||
1844 | |||
1845 | if (descr) | ||
1846 | { | ||
1847 | header_set_value (hdr, MU_HEADER_CONTENT_DESCRIPTION, descr, 1); | ||
1848 | free (descr); | ||
1849 | } | ||
1850 | |||
1851 | finish_msg (env, &msg); | ||
1852 | return status; | ||
1746 | } | 1853 | } |
1747 | 1854 | ||
1748 | int | 1855 | int |
... | @@ -2013,7 +2120,7 @@ mhn_compose () | ... | @@ -2013,7 +2120,7 @@ mhn_compose () |
2013 | stream_t stream, in; | 2120 | stream_t stream, in; |
2014 | struct compose_env env; | 2121 | struct compose_env env; |
2015 | message_t msg; | 2122 | message_t msg; |
2016 | char *name; | 2123 | char *name, *backup, *p; |
2017 | 2124 | ||
2018 | mime_create (&mime, NULL, 0); | 2125 | mime_create (&mime, NULL, 0); |
2019 | 2126 | ||
... | @@ -2029,7 +2136,23 @@ mhn_compose () | ... | @@ -2029,7 +2136,23 @@ mhn_compose () |
2029 | return rc; | 2136 | return rc; |
2030 | 2137 | ||
2031 | mime_get_message (mime, &msg); | 2138 | mime_get_message (mime, &msg); |
2032 | asprintf (&name, "%s/draft.mhn", mu_path_folder_dir); | 2139 | |
2140 | p = strrchr (input_file, '/'); | ||
2141 | /* Prepare file names */ | ||
2142 | if (p) | ||
2143 | { | ||
2144 | *p = 0; | ||
2145 | name = mu_tempname (input_file); | ||
2146 | asprintf (&backup, "%s/,%s.orig", input_file, p + 1); | ||
2147 | *p = '/'; | ||
2148 | } | ||
2149 | else | ||
2150 | { | ||
2151 | name = mu_tempname (NULL); | ||
2152 | asprintf (&backup, ",%s.orig", input_file); | ||
2153 | } | ||
2154 | |||
2155 | /* Create working draft file */ | ||
2033 | unlink (name); | 2156 | unlink (name); |
2034 | rc = file_stream_create (&stream, name, MU_STREAM_RDWR|MU_STREAM_CREAT); | 2157 | rc = file_stream_create (&stream, name, MU_STREAM_RDWR|MU_STREAM_CREAT); |
2035 | if (rc) | 2158 | if (rc) |
... | @@ -2048,12 +2171,20 @@ mhn_compose () | ... | @@ -2048,12 +2171,20 @@ mhn_compose () |
2048 | stream_destroy (&stream, stream_get_owner (stream)); | 2171 | stream_destroy (&stream, stream_get_owner (stream)); |
2049 | return rc; | 2172 | return rc; |
2050 | } | 2173 | } |
2051 | free (name); | ||
2052 | 2174 | ||
2053 | copy_header (message, stream); | 2175 | copy_header (message, stream); |
2054 | message_get_stream (msg, &in); | 2176 | message_get_stream (msg, &in); |
2055 | cat_message (stream, in); | 2177 | cat_message (stream, in); |
2056 | stream_destroy (&stream, stream_get_owner (stream)); | 2178 | stream_destroy (&stream, stream_get_owner (stream)); |
2179 | |||
2180 | /* Preserve the backup copy and replace the draft */ | ||
2181 | unlink (backup); | ||
2182 | rename (input_file, backup); | ||
2183 | rename (name, input_file); | ||
2184 | |||
2185 | free (name); | ||
2186 | free (input_file); | ||
2187 | |||
2057 | return 0; | 2188 | return 0; |
2058 | } | 2189 | } |
2059 | 2190 | ... | ... |
-
Please register or sign in to post a comment