Commit 6187f41e 6187f41e91d974a8f0a8688f1f4b552b0ab6e33a by Sergey Poznyakoff

(mail_sendheader,send_append_header,send_append_header2)

1 parent 3dc6cff3
...@@ -193,6 +193,7 @@ extern int mail_quit __P ((int argc, char **argv)); ...@@ -193,6 +193,7 @@ extern int mail_quit __P ((int argc, char **argv));
193 extern int mail_reply __P ((int argc, char **argv)); 193 extern int mail_reply __P ((int argc, char **argv));
194 extern int mail_retain __P ((int argc, char **argv)); 194 extern int mail_retain __P ((int argc, char **argv));
195 extern int mail_save __P ((int argc, char **argv)); 195 extern int mail_save __P ((int argc, char **argv));
196 extern int mail_sendheader __P((int argc, char **argv));
196 extern int mail_set __P ((int argc, char **argv)); 197 extern int mail_set __P ((int argc, char **argv));
197 extern int mail_shell __P ((int argc, char **argv)); 198 extern int mail_shell __P ((int argc, char **argv));
198 extern int mail_execute __P((int shell, int argc, char **argv)); 199 extern int mail_execute __P((int shell, int argc, char **argv));
...@@ -232,6 +233,9 @@ extern int mail_header_is_unfoldable __P((char *str)); ...@@ -232,6 +233,9 @@ extern int mail_header_is_unfoldable __P((char *str));
232 extern int mail_mbox_close __P ((void)); 233 extern int mail_mbox_close __P ((void));
233 extern char *mail_expand_name __P((const char *name)); 234 extern char *mail_expand_name __P((const char *name));
234 235
236 extern void send_append_header __P((char *text));
237 extern void send_append_header2 __P((char *name, char *value, int mode));
238
235 extern int var_shell __P ((int argc, char **argv, compose_env_t *env)); 239 extern int var_shell __P ((int argc, char **argv, compose_env_t *env));
236 extern int var_command __P ((int argc, char **argv, compose_env_t *env)); 240 extern int var_command __P ((int argc, char **argv, compose_env_t *env));
237 extern int var_help __P ((int argc, char **argv, compose_env_t *env)); 241 extern int var_help __P ((int argc, char **argv, compose_env_t *env));
......
...@@ -25,6 +25,116 @@ ...@@ -25,6 +25,116 @@
25 static int isfilename __P ((const char *)); 25 static int isfilename __P ((const char *));
26 static void msg_to_pipe __P ((const char *cmd, message_t msg)); 26 static void msg_to_pipe __P ((const char *cmd, message_t msg));
27 27
28
29 /* Additional message headers */
30 struct add_header
31 {
32 int mode;
33 char *name;
34 char *value;
35 };
36
37 static list_t add_header_list;
38
39 static int
40 seed_headers (void *item, void *data)
41 {
42 struct add_header *hp = item;
43 compose_env_t *env = data;
44
45 compose_header_set (env, hp->name, hp->value, hp->mode);
46 return 0;
47 }
48
49 static int
50 list_headers (void *item, void *data)
51 {
52 struct add_header *hp = item;
53 char *name = data;
54
55 if (!name || strcmp (name, hp->name) == 0)
56 {
57 printf ("%s: %s\n", hp->name, hp->value);
58 }
59 return 0;
60 }
61
62 static void
63 add_header (char *name, char *value, int mode)
64 {
65 struct add_header *hp;
66
67 if (!add_header_list)
68 {
69 int rc = list_create (&add_header_list);
70 if (rc)
71 {
72 util_error (_("Cannot create header list: %s"), mu_strerror (rc));
73 exit (1);
74 }
75 }
76
77 hp = xmalloc (sizeof (*hp));
78 hp->mode = mode;
79 hp->name = name;
80 hp->value = value;
81 list_append (add_header_list, hp);
82 }
83
84 void
85 send_append_header (char *text)
86 {
87 char *p;
88 size_t len;
89 char *name;
90
91 p = strchr (text, ':');
92 if (!p)
93 {
94 util_error (_("Invalid header: %s"), text);
95 return;
96 }
97 len = p - text;
98 name = xmalloc (len + 1);
99 memcpy (name, text, len);
100 name[len] = 0;
101 for (p++; *p && isspace (*p); p++)
102 ;
103
104 add_header (name, strdup (p), COMPOSE_APPEND);
105 }
106
107 void
108 send_append_header2 (char *name, char *value, int mode)
109 {
110 add_header (strdup (name), strdup (value), mode);
111 }
112
113 int
114 mail_sendheader (int argc, char **argv)
115 {
116 if (argc == 1)
117 list_do (add_header_list, list_headers, NULL);
118 else if (argc == 2)
119 {
120 if (strchr (argv[1], ':'))
121 send_append_header (argv[1]);
122 else
123 list_do (add_header_list, list_headers, argv[1]);
124 }
125 else
126 {
127 size_t len = strlen (argv[1]);
128 if (len > 0 && argv[1][len - 1] == ':')
129 argv[1][len - 1] = 0;
130 add_header (strdup (argv[1]), strdup (argv[2]), COMPOSE_APPEND);
131 }
132 return 0;
133 }
134
135
136 /* Send-related commands */
137
28 static void 138 static void
29 read_cc_bcc (compose_env_t *env) 139 read_cc_bcc (compose_env_t *env)
30 { 140 {
...@@ -92,12 +202,6 @@ mail_send (int argc, char **argv) ...@@ -92,12 +202,6 @@ mail_send (int argc, char **argv)
92 if (util_getenv (NULL, "asksub", Mail_env_boolean, 0) == 0) 202 if (util_getenv (NULL, "asksub", Mail_env_boolean, 0) == 0)
93 compose_header_set (&env, MU_HEADER_SUBJECT, 203 compose_header_set (&env, MU_HEADER_SUBJECT,
94 ml_readline_with_intr ("Subject: "), COMPOSE_REPLACE); 204 ml_readline_with_intr ("Subject: "), COMPOSE_REPLACE);
95 else
96 {
97 char *p;
98 if (util_getenv (&p, "subject", Mail_env_string, 0) == 0)
99 compose_header_set (&env, MU_HEADER_SUBJECT, p, COMPOSE_REPLACE);
100 }
101 205
102 status = mail_send0 (&env, save_to); 206 status = mail_send0 (&env, save_to);
103 compose_destroy (&env); 207 compose_destroy (&env);
...@@ -108,6 +212,7 @@ void ...@@ -108,6 +212,7 @@ void
108 compose_init (compose_env_t * env) 212 compose_init (compose_env_t * env)
109 { 213 {
110 memset (env, 0, sizeof (*env)); 214 memset (env, 0, sizeof (*env));
215 list_do (add_header_list, seed_headers, env);
111 } 216 }
112 217
113 int 218 int
......