Commit a7645e9a a7645e9a99a26f4d0447846aa19c4cf5fb5a44dd by Sergey Poznyakoff

Implemented ~A (read signature from file).

1 parent c506ffde
Showing 1 changed file with 69 additions and 43 deletions
...@@ -32,7 +32,7 @@ var_shell(int argc, char **argv, struct send_environ *env) ...@@ -32,7 +32,7 @@ var_shell(int argc, char **argv, struct send_environ *env)
32 { 32 {
33 int status; 33 int status;
34 ofile = env->ofile; 34 ofile = env->ofile;
35 status = mail_shell (argc, argv); 35 status = mail_shell(argc, argv);
36 ofile = env->file; 36 ofile = env->file;
37 return status; 37 return status;
38 } 38 }
...@@ -47,7 +47,7 @@ var_command(int argc, char **argv, struct send_environ *env) ...@@ -47,7 +47,7 @@ var_command(int argc, char **argv, struct send_environ *env)
47 47
48 if (argv[1][0] == '#') 48 if (argv[1][0] == '#')
49 return 0; 49 return 0;
50 entry = util_find_entry (mail_command_table, argv[1]); 50 entry = util_find_entry(mail_command_table, argv[1]);
51 if (!entry.func) 51 if (!entry.func)
52 { 52 {
53 util_error("Unknown command: %s", argv[1]); 53 util_error("Unknown command: %s", argv[1]);
...@@ -70,13 +70,13 @@ int ...@@ -70,13 +70,13 @@ int
70 var_help(int argc, char **argv, struct send_environ *env) 70 var_help(int argc, char **argv, struct send_environ *env)
71 { 71 {
72 if (argc < 2) 72 if (argc < 2)
73 return util_help (mail_escape_table, NULL); 73 return util_help(mail_escape_table, NULL);
74 else 74 else
75 { 75 {
76 int status = 0; 76 int status = 0;
77 77
78 while (--argc) 78 while (--argc)
79 status |= util_help (mail_escape_table, *++argv); 79 status |= util_help(mail_escape_table, *++argv);
80 80
81 return status; 81 return status;
82 } 82 }
...@@ -94,7 +94,32 @@ var_sign(int argc, char **argv, struct send_environ *env) ...@@ -94,7 +94,32 @@ var_sign(int argc, char **argv, struct send_environ *env)
94 else 94 else
95 p = util_find_env("sign"); 95 p = util_find_env("sign");
96 if (p->set) 96 if (p->set)
97 fprintf (ofile, "%s", p->value); 97 {
98 if (isupper(argv[0][0]))
99 {
100 char *name = util_fullpath(p->value);
101 FILE *fp = fopen(name, "r");
102 char *buf = NULL;
103 size_t n = 0;
104
105 if (!fp)
106 {
107 util_error("can't open %s: %s", name, strerror(errno));
108 free(name);
109 }
110
111 fprintf(stdout, "Reading %s\n", name);
112 while (getline(&buf, &n, fp) > 0)
113 fprintf(ofile, "%s", buf);
114
115 fclose(fp);
116 free(buf);
117 free(name);
118 }
119 else
120 fprintf(ofile, "%s", p->value);
121 var_continue();
122 }
98 else 123 else
99 util_error("\"sign\" not set"); 124 util_error("\"sign\" not set");
100 return 0; 125 return 0;
...@@ -122,22 +147,22 @@ var_cc(int argc, char **argv, struct send_environ *env) ...@@ -122,22 +147,22 @@ var_cc(int argc, char **argv, struct send_environ *env)
122 int 147 int
123 var_deadletter(int argc, char **argv, struct send_environ *env) 148 var_deadletter(int argc, char **argv, struct send_environ *env)
124 { 149 {
125 FILE *dead = fopen (getenv("DEAD"), "r"); 150 FILE *dead = fopen(getenv("DEAD"), "r");
126 int c; 151 int c;
127 152
128 while ((c = fgetc(dead)) != EOF) 153 while ((c = fgetc(dead)) != EOF)
129 fputc (c, ofile); 154 fputc(c, ofile);
130 fclose (dead); 155 fclose(dead);
131 return 0; 156 return 0;
132 } 157 }
133 158
134 static int 159 static int
135 var_run_editor(char *ed, int argc, char **argv, struct send_environ *env) 160 var_run_editor(char *ed, int argc, char **argv, struct send_environ *env)
136 { 161 {
137 fclose (env->file); 162 fclose(env->file);
138 ofile = env->ofile; 163 ofile = env->ofile;
139 util_do_command ("!%s %s", ed, env->filename); 164 util_do_command("!%s %s", ed, env->filename);
140 env->file = fopen (env->filename, "a+"); 165 env->file = fopen(env->filename, "a+");
141 ofile = env->file; 166 ofile = env->file;
142 var_continue(); 167 var_continue();
143 return 0; 168 return 0;
...@@ -169,10 +194,10 @@ var_print(int argc, char **argv, struct send_environ *env) ...@@ -169,10 +194,10 @@ var_print(int argc, char **argv, struct send_environ *env)
169 int 194 int
170 var_headers(int argc, char **argv, struct send_environ *env) 195 var_headers(int argc, char **argv, struct send_environ *env)
171 { 196 {
172 ml_reread("To:", &env->to); 197 ml_reread("To: ", &env->to);
173 ml_reread("Cc:", &env->cc); 198 ml_reread("Cc: ", &env->cc);
174 ml_reread("Bcc:", &env->bcc); 199 ml_reread("Bcc: ", &env->bcc);
175 ml_reread("Subject:", &env->subj); 200 ml_reread("Subject: ", &env->subj);
176 var_continue(); 201 var_continue();
177 return 0; 202 return 0;
178 } 203 }
...@@ -181,7 +206,7 @@ var_headers(int argc, char **argv, struct send_environ *env) ...@@ -181,7 +206,7 @@ var_headers(int argc, char **argv, struct send_environ *env)
181 int 206 int
182 var_insert(int argc, char **argv, struct send_environ *env) 207 var_insert(int argc, char **argv, struct send_environ *env)
183 { 208 {
184 fprintf (ofile, "%s", util_find_env(argv[1])->value); 209 fprintf(ofile, "%s", util_find_env(argv[1])->value);
185 return 1; 210 return 1;
186 } 211 }
187 212
...@@ -191,7 +216,7 @@ int ...@@ -191,7 +216,7 @@ int
191 var_quote(int argc, char **argv, struct send_environ *env) 216 var_quote(int argc, char **argv, struct send_environ *env)
192 { 217 {
193 if (argc > 1) 218 if (argc > 1)
194 return util_msglist_command (var_quote, argc, argv, 0); 219 return util_msglist_command(var_quote, argc, argv, 0);
195 else 220 else
196 { 221 {
197 message_t mesg; 222 message_t mesg;
...@@ -201,9 +226,9 @@ var_quote(int argc, char **argv, struct send_environ *env) ...@@ -201,9 +226,9 @@ var_quote(int argc, char **argv, struct send_environ *env)
201 char buffer[512]; 226 char buffer[512];
202 off_t off = 0; 227 off_t off = 0;
203 size_t n = 0; 228 size_t n = 0;
204 char *prefix = util_find_env ("indentprefix")->value; 229 char *prefix = util_find_env("indentprefix")->value;
205 230
206 if (mailbox_get_message (mbox, cursor, &mesg) != 0) 231 if (mailbox_get_message(mbox, cursor, &mesg) != 0)
207 return 1; 232 return 1;
208 233
209 fprintf(stdout, "Interpolating: %d\n", cursor); 234 fprintf(stdout, "Interpolating: %d\n", cursor);
...@@ -213,32 +238,32 @@ var_quote(int argc, char **argv, struct send_environ *env) ...@@ -213,32 +238,32 @@ var_quote(int argc, char **argv, struct send_environ *env)
213 size_t i, num = 0; 238 size_t i, num = 0;
214 char buffer[512]; 239 char buffer[512];
215 240
216 message_get_header (mesg, &hdr); 241 message_get_header(mesg, &hdr);
217 header_get_field_count (hdr, &num); 242 header_get_field_count(hdr, &num);
218 243
219 for (i = 1; i <= num; i++) 244 for (i = 1; i <= num; i++)
220 { 245 {
221 header_get_field_name (hdr, i, buffer, sizeof(buffer), NULL); 246 header_get_field_name(hdr, i, buffer, sizeof(buffer), NULL);
222 if (mail_header_is_visible (buffer)) 247 if (mail_header_is_visible(buffer))
223 { 248 {
224 fprintf (ofile, "%s%s: ", prefix, buffer); 249 fprintf(ofile, "%s%s: ", prefix, buffer);
225 header_get_field_value (hdr, i, buffer, sizeof(buffer), 250 header_get_field_value(hdr, i, buffer, sizeof(buffer),
226 NULL); 251 NULL);
227 fprintf (ofile, "%s\n", buffer); 252 fprintf(ofile, "%s\n", buffer);
228 } 253 }
229 } 254 }
230 fprintf (ofile, "\n"); 255 fprintf(ofile, "\n");
231 message_get_body (mesg, &body); 256 message_get_body(mesg, &body);
232 body_get_stream (body, &stream); 257 body_get_stream(body, &stream);
233 } 258 }
234 else 259 else
235 message_get_stream (mesg, &stream); 260 message_get_stream(mesg, &stream);
236 261
237 while (stream_readline(stream, buffer, sizeof(buffer) - 1, off, &n) == 0 262 while (stream_readline(stream, buffer, sizeof(buffer) - 1, off, &n) == 0
238 && n != 0) 263 && n != 0)
239 { 264 {
240 buffer[n] = '\0'; 265 buffer[n] = '\0';
241 fprintf (ofile, "%s%s", prefix, buffer); 266 fprintf(ofile, "%s%s", prefix, buffer);
242 off += n; 267 off += n;
243 } 268 }
244 var_continue(); 269 var_continue();
...@@ -353,7 +378,7 @@ var_write(int argc, char **argv, struct send_environ *env) ...@@ -353,7 +378,7 @@ var_write(int argc, char **argv, struct send_environ *env)
353 int 378 int
354 var_exit(int argc, char **argv, struct send_environ *env) 379 var_exit(int argc, char **argv, struct send_environ *env)
355 { 380 {
356 return util_do_command ("quit"); 381 return util_do_command("quit");
357 } 382 }
358 383
359 /* ~|[shell-command] */ 384 /* ~|[shell-command] */
...@@ -364,6 +389,12 @@ var_pipe(int argc, char **argv, struct send_environ *env) ...@@ -364,6 +389,12 @@ var_pipe(int argc, char **argv, struct send_environ *env)
364 pid_t pid; 389 pid_t pid;
365 int fd; 390 int fd;
366 391
392 if (argc == 1)
393 {
394 util_error("pipe: no command specified");
395 return 1;
396 }
397
367 if (pipe(p)) 398 if (pipe(p))
368 { 399 {
369 util_error("pipe: %s", strerror(errno)); 400 util_error("pipe: %s", strerror(errno));
...@@ -399,12 +430,7 @@ var_pipe(int argc, char **argv, struct send_environ *env) ...@@ -399,12 +430,7 @@ var_pipe(int argc, char **argv, struct send_environ *env)
399 close(fd); 430 close(fd);
400 431
401 /* Execute the process */ 432 /* Execute the process */
402 xargv = calloc(argc, sizeof(xargv[0])); 433 xargv = util_calloc(argc, sizeof(xargv[0]));
403 if (!xargv)
404 {
405 util_error("not enough memory");
406 exit(1);
407 }
408 for (i = 0; i < argc-1; i++) 434 for (i = 0; i < argc-1; i++)
409 xargv[i] = argv[i+1]; 435 xargv[i] = argv[i+1];
410 xargv[i] = NULL; 436 xargv[i] = NULL;
...@@ -430,7 +456,7 @@ var_pipe(int argc, char **argv, struct send_environ *env) ...@@ -430,7 +456,7 @@ var_pipe(int argc, char **argv, struct send_environ *env)
430 env->file = fopen(env->filename, "r"); 456 env->file = fopen(env->filename, "r");
431 457
432 lines = size = 0; 458 lines = size = 0;
433 while (getline (&buf, &n, env->file) > 0) 459 while (getline(&buf, &n, env->file) > 0)
434 { 460 {
435 lines++; 461 lines++;
436 size += n; 462 size += n;
...@@ -455,10 +481,10 @@ var_pipe(int argc, char **argv, struct send_environ *env) ...@@ -455,10 +481,10 @@ var_pipe(int argc, char **argv, struct send_environ *env)
455 rc = 0; 481 rc = 0;
456 } 482 }
457 483
458 fprintf(stdout, "\"|%s\" out: %d/%d ", argv[1], lines, size); 484 fprintf(stdout, "\"|%s\" in: %d/%d ", argv[1], lines, size);
459 if (rc) 485 if (rc)
460 { 486 {
461 fprintf(stdout, "no lines in\n"); 487 fprintf(stdout, "no lines out\n");
462 } 488 }
463 else 489 else
464 { 490 {
...@@ -469,7 +495,7 @@ var_pipe(int argc, char **argv, struct send_environ *env) ...@@ -469,7 +495,7 @@ var_pipe(int argc, char **argv, struct send_environ *env)
469 env->file = fopen(env->filename, "w+"); 495 env->file = fopen(env->filename, "w+");
470 496
471 lines = size = 0; 497 lines = size = 0;
472 while (getline (&buf, &n, fp) > 0) 498 while (getline(&buf, &n, fp) > 0)
473 { 499 {
474 lines++; 500 lines++;
475 size += n; 501 size += n;
...@@ -477,7 +503,7 @@ var_pipe(int argc, char **argv, struct send_environ *env) ...@@ -477,7 +503,7 @@ var_pipe(int argc, char **argv, struct send_environ *env)
477 } 503 }
478 fclose(env->file); 504 fclose(env->file);
479 505
480 fprintf(stdout, "in: %d/%d\n", lines, size); 506 fprintf(stdout, "out: %d/%d\n", lines, size);
481 } 507 }
482 508
483 /* Clean up the things */ 509 /* Clean up the things */
......