Commit 9f726ee0 9f726ee08feeefd295bd5b2e3f6c676d2248f3f5 by Sergey Poznyakoff

mail: Implement folder completion in "save"

* mail/mailline.c (file_compl_internal): New function (from file_compl);
(file_compl): Call file_compl_internal.
(msglist_file_compl): Call file_compl_internal.
1 parent b4d7b1a6
...@@ -291,14 +291,6 @@ msglist_compl (int argc, char **argv, int ws) ...@@ -291,14 +291,6 @@ msglist_compl (int argc, char **argv, int ws)
291 } 291 }
292 292
293 char ** 293 char **
294 msglist_file_compl (int argc, char **argv, int ws MU_ARG_UNUSED)
295 {
296 if (argc == 1)
297 ml_attempted_completion_over ();
298 return NULL;
299 }
300
301 char **
302 command_compl (int argc, char **argv, int ws) 294 command_compl (int argc, char **argv, int ws)
303 { 295 {
304 ml_set_completion_append_character (0); 296 ml_set_completion_append_character (0);
...@@ -413,8 +405,102 @@ folder_generator (const char *text, int state) ...@@ -413,8 +405,102 @@ folder_generator (const char *text, int state)
413 return ret; 405 return ret;
414 } 406 }
415 407
416 char ** 408 static char *
417 file_compl (int argc, char **argv, int ws) 409 msgtype_generator (const char *text, int state)
410 {
411 static char types[] = "dnorTtu";
412 static int i;
413 char *s;
414
415 if (!state)
416 {
417 if (text[1])
418 return NULL;
419 i = 0;
420 }
421 if (!types[i])
422 return NULL;
423 s = malloc (2);
424 if (s)
425 {
426 s[0] = types[i++];
427 s[1] = 0;
428 }
429 return s;
430 }
431
432 static char *
433 header_generator (const char *text, int state)
434 {
435 static int i, len;
436 char *hdr;
437 char *hdrlist[] = {
438 MU_HEADER_RETURN_PATH,
439 MU_HEADER_RECEIVED,
440 MU_HEADER_DATE,
441 MU_HEADER_DCC,
442 MU_HEADER_FROM,
443 MU_HEADER_SENDER,
444 MU_HEADER_RESENT_FROM,
445 MU_HEADER_SUBJECT,
446 MU_HEADER_RESENT_SENDER,
447 MU_HEADER_TO,
448 MU_HEADER_RESENT_TO,
449 MU_HEADER_CC,
450 MU_HEADER_RESENT_CC,
451 MU_HEADER_BCC,
452 MU_HEADER_RESENT_BCC,
453 MU_HEADER_REPLY_TO,
454 MU_HEADER_RESENT_REPLY_TO,
455 MU_HEADER_MESSAGE_ID,
456 MU_HEADER_RESENT_MESSAGE_ID,
457 MU_HEADER_IN_REPLY_TO,
458 MU_HEADER_REFERENCE,
459 MU_HEADER_REFERENCES,
460 MU_HEADER_ENCRYPTED,
461 MU_HEADER_PRECEDENCE,
462 MU_HEADER_STATUS,
463 MU_HEADER_CONTENT_LENGTH,
464 MU_HEADER_CONTENT_LANGUAGE,
465 MU_HEADER_CONTENT_TRANSFER_ENCODING,
466 MU_HEADER_CONTENT_ID,
467 MU_HEADER_CONTENT_TYPE,
468 MU_HEADER_CONTENT_DESCRIPTION,
469 MU_HEADER_CONTENT_DISPOSITION,
470 MU_HEADER_CONTENT_MD5,
471 MU_HEADER_CONTENT_LOCATION,
472 MU_HEADER_MIME_VERSION,
473 MU_HEADER_X_MAILER,
474 MU_HEADER_X_UIDL,
475 MU_HEADER_X_UID,
476 MU_HEADER_X_IMAPBASE,
477 MU_HEADER_ENV_SENDER,
478 MU_HEADER_ENV_DATE,
479 MU_HEADER_FCC,
480 MU_HEADER_DELIVERY_DATE,
481 MU_HEADER_ENVELOPE_TO,
482 MU_HEADER_X_EXPIRE_TIMESTAMP,
483 NULL
484 };
485
486 if (!state)
487 {
488 i = 0;
489 len = strlen (text);
490 }
491
492 while ((hdr = hdrlist[i]))
493 {
494 i++;
495 if (mu_c_strncasecmp (hdr, text, len) == 0)
496 return strdup (hdr);
497 }
498
499 return NULL;
500 }
501
502 static char **
503 file_compl_internal (int argc, char **argv, int ws, int msglist)
418 { 504 {
419 char *text; 505 char *text;
420 506
...@@ -426,12 +512,33 @@ file_compl (int argc, char **argv, int ws) ...@@ -426,12 +512,33 @@ file_compl (int argc, char **argv, int ws)
426 } 512 }
427 513
428 text = argv[argc-1]; 514 text = argv[argc-1];
515
516 if (msglist)
517 {
518 if (text[0] == ':')
519 {
520 ml_set_completion_append_character (' ');
521 return rl_completion_matches (text, msgtype_generator);
522 }
523 else if (mu_isalpha (text[0]))
524 {
525 ml_set_completion_append_character (':');
526 return rl_completion_matches (text, header_generator);
527 }
528 else if (mu_isdigit (text[0]))
529 {
530 ml_attempted_completion_over ();
531 return NULL;
532 }
533 }
534
429 switch (text[0]) 535 switch (text[0])
430 { 536 {
431 case '+': 537 case '+':
432 text++; 538 text++;
433 break; 539 break;
434 540
541 case '%':
435 case '#': 542 case '#':
436 case '&': 543 case '&':
437 ml_attempted_completion_over (); 544 ml_attempted_completion_over ();
...@@ -444,6 +551,18 @@ file_compl (int argc, char **argv, int ws) ...@@ -444,6 +551,18 @@ file_compl (int argc, char **argv, int ws)
444 return rl_completion_matches (text, folder_generator); 551 return rl_completion_matches (text, folder_generator);
445 } 552 }
446 553
554 char **
555 file_compl (int argc, char **argv, int ws)
556 {
557 return file_compl_internal (argc, argv, ws, 0);
558 }
559
560 char **
561 msglist_file_compl (int argc, char **argv, int ws)
562 {
563 return file_compl_internal (argc, argv, ws, 1);
564 }
565
447 static char * 566 static char *
448 dir_generator (const char *text, int state) 567 dir_generator (const char *text, int state)
449 { 568 {
...@@ -944,4 +1063,3 @@ ml_attempted_completion_over () ...@@ -944,4 +1063,3 @@ ml_attempted_completion_over ()
944 } 1063 }
945 1064
946 #endif 1065 #endif
947
......