pop3client.c:
minor buf fixing. nntpclient.c : adusted to the new API
Showing
2 changed files
with
465 additions
and
46 deletions
... | @@ -32,6 +32,7 @@ | ... | @@ -32,6 +32,7 @@ |
32 | #include <termios.h> | 32 | #include <termios.h> |
33 | #include <signal.h> | 33 | #include <signal.h> |
34 | #include <ctype.h> | 34 | #include <ctype.h> |
35 | #include <time.h> | ||
35 | 36 | ||
36 | #ifdef WITH_READLINE | 37 | #ifdef WITH_READLINE |
37 | # include <readline/readline.h> | 38 | # include <readline/readline.h> |
... | @@ -57,23 +58,31 @@ COMMAND; | ... | @@ -57,23 +58,31 @@ COMMAND; |
57 | /* The names of functions that actually do the manipulation. */ | 58 | /* The names of functions that actually do the manipulation. */ |
58 | int com_article (char *); | 59 | int com_article (char *); |
59 | int com_body (char *); | 60 | int com_body (char *); |
61 | int com_connect (char *); | ||
60 | int com_date (char *); | 62 | int com_date (char *); |
63 | int com_disconnect (char *); | ||
64 | int com_exit (char *); | ||
61 | int com_group (char *); | 65 | int com_group (char *); |
62 | int com_head (char *); | 66 | int com_head (char *); |
67 | int com_help (char *); | ||
68 | int com_ihave (char *); | ||
69 | int com_info (char *); | ||
63 | int com_last (char *); | 70 | int com_last (char *); |
71 | int com_list (char *); | ||
72 | int com_list_active (char *); | ||
73 | int com_list_active_times (char *); | ||
74 | int com_list_distributions (char *); | ||
75 | int com_list_distribpats (char *); | ||
64 | int com_list_extensions (char *); | 76 | int com_list_extensions (char *); |
77 | int com_list_newsgoups (char *); | ||
78 | int com_mode (char *); | ||
65 | int com_mode_reader (char *); | 79 | int com_mode_reader (char *); |
80 | int com_newgroups (char *); | ||
81 | int com_newnews (char *); | ||
66 | int com_next (char *); | 82 | int com_next (char *); |
83 | int com_post (char *); | ||
67 | int com_quit (char *); | 84 | int com_quit (char *); |
68 | int com_mode_reader (char *); | ||
69 | |||
70 | int com_exit (char *); | ||
71 | |||
72 | int com_help (char *); | ||
73 | int com_stat (char *); | 85 | int com_stat (char *); |
74 | |||
75 | int com_connect (char *); | ||
76 | int com_disconnect (char *); | ||
77 | int com_verbose (char *); | 86 | int com_verbose (char *); |
78 | 87 | ||
79 | void initialize_readline (void); | 88 | void initialize_readline (void); |
... | @@ -86,28 +95,27 @@ int valid_argument (const char *, char *); | ... | @@ -86,28 +95,27 @@ int valid_argument (const char *, char *); |
86 | void sig_int (int); | 95 | void sig_int (int); |
87 | 96 | ||
88 | COMMAND commands[] = { | 97 | COMMAND commands[] = { |
89 | {"mode reader", com_mode_reader, "Set mode reader: MODE READER"}, | ||
90 | {"list extensions", com_list_extensions, "List extensions: LIST EXTENSIONS"}, | ||
91 | {"quit", com_quit, "Terminate the session: QUIT"}, | ||
92 | {"group", com_group, "Select a group: GROUP group"}, | ||
93 | {"next", com_next, "Set current to the next article: NEXT"}, | ||
94 | {"last", com_last, "Set current to the previous article: LAST"}, | ||
95 | |||
96 | {"article", com_article, "Retrieve an article: ARTICLE [message_id|number]"}, | 98 | {"article", com_article, "Retrieve an article: ARTICLE [message_id|number]"}, |
97 | {"header", com_head, "Retrieve the head of an article: HEAD [message_id|number]"}, | ||
98 | {"body", com_body, "Retrieve the body of an article: BODY [message_id|number]"}, | 99 | {"body", com_body, "Retrieve the body of an article: BODY [message_id|number]"}, |
99 | |||
100 | {"date", com_date, "Server date: DATE"}, | ||
101 | {"stat", com_stat, "Check the status of an article : STAT [message_id|number]"}, | ||
102 | |||
103 | {"connect", com_connect, "Open connection: connect hostname [port]"}, | 100 | {"connect", com_connect, "Open connection: connect hostname [port]"}, |
101 | {"date", com_date, "Server date: DATE"}, | ||
104 | {"disconnect", com_disconnect, "Close connection: disconnect"}, | 102 | {"disconnect", com_disconnect, "Close connection: disconnect"}, |
105 | |||
106 | {"verbose", com_verbose, "Enable Protocol tracing: verbose [on|off]"}, | ||
107 | {"exit", com_exit, "exit program"}, | 103 | {"exit", com_exit, "exit program"}, |
108 | 104 | {"group", com_group, "Select a group: GROUP group"}, | |
109 | {"help", com_help, "Display this text"}, | 105 | {"head", com_head, "Retrieve the head of an article: HEAD [message_id|number]"}, |
110 | {"?", com_help, "Synonym for `help'"}, | 106 | {"help", com_help, "Ask the server for info: HELP"}, |
107 | {"ihave", com_ihave, "Transfer an article to the server : IHAVE <<enter the article, finish with a '.' or ctrl-D>>"}, | ||
108 | {"last", com_last, "Set current to the previous article: LAST"}, | ||
109 | {"list", com_list, "List : LIST [ACTIVE|ACTIVE.TIMES|DISTRIB.PATS|DISTRIBUTIONS|EXTENSIONS|NEWSGROUPS]"}, | ||
110 | {"mode", com_mode, "Set mode reader: MODE READER"}, | ||
111 | {"newgroups", com_newgroups, "Ask for new groups : NEWGROUPS [yyyymmdd hhmmss [GMT]]"}, | ||
112 | {"newnews", com_newnews, "Ask for new news : NEWNEWS wildmat [yyyymmdd hhmmss]"}, | ||
113 | {"next", com_next, "Set current to the next article: NEXT"}, | ||
114 | {"post", com_post, "Post an article to the server : POST <<enter the article, finish with a '.' or ctrl-D>>"}, | ||
115 | {"quit", com_quit, "Terminate the session: QUIT"}, | ||
116 | {"stat", com_stat, "Check the status of an article : STAT [message_id|number]"}, | ||
117 | {"verbose", com_verbose, "Enable Protocol tracing: verbose {on|off}"}, | ||
118 | {"?", com_info, "Dysplay this help"}, | ||
111 | {NULL, NULL, NULL} | 119 | {NULL, NULL, NULL} |
112 | }; | 120 | }; |
113 | 121 | ||
... | @@ -365,7 +373,7 @@ com_verbose (char *arg) | ... | @@ -365,7 +373,7 @@ com_verbose (char *arg) |
365 | verbose = (strcmp (arg, "on") == 0); | 373 | verbose = (strcmp (arg, "on") == 0); |
366 | if (nntp != NULL) | 374 | if (nntp != NULL) |
367 | { | 375 | { |
368 | if (verbose == 1) | 376 | if (verbose) |
369 | { | 377 | { |
370 | mu_debug_t debug; | 378 | mu_debug_t debug; |
371 | mu_debug_create (&debug, NULL); | 379 | mu_debug_create (&debug, NULL); |
... | @@ -380,6 +388,15 @@ com_verbose (char *arg) | ... | @@ -380,6 +388,15 @@ com_verbose (char *arg) |
380 | return status; | 388 | return status; |
381 | } | 389 | } |
382 | 390 | ||
391 | int com_mode (char *arg) | ||
392 | { | ||
393 | if (!valid_argument("mode", arg)) | ||
394 | return EINVAL; | ||
395 | if (strncasecmp (arg, "READER", 6) == 0) | ||
396 | return com_mode_reader (arg); | ||
397 | return EINVAL; | ||
398 | } | ||
399 | |||
383 | int | 400 | int |
384 | com_mode_reader (char *arg ARG_UNUSED) | 401 | com_mode_reader (char *arg ARG_UNUSED) |
385 | { | 402 | { |
... | @@ -455,11 +472,11 @@ com_article (char *arg) | ... | @@ -455,11 +472,11 @@ com_article (char *arg) |
455 | return EINVAL; | 472 | return EINVAL; |
456 | 473 | ||
457 | if ((arg == NULL || *arg == '\0') || (arg != NULL && *arg == '<')) | 474 | if ((arg == NULL || *arg == '\0') || (arg != NULL && *arg == '<')) |
458 | status = mu_nntp_body_id (nntp, arg, NULL, NULL, &stream); | 475 | status = mu_nntp_article_id (nntp, arg, NULL, NULL, &stream); |
459 | else | 476 | else |
460 | { | 477 | { |
461 | unsigned long number = strtoul (arg, NULL, 10); | 478 | unsigned long number = strtoul (arg, NULL, 10); |
462 | status = mu_nntp_body (nntp, number, NULL, NULL, &stream); | 479 | status = mu_nntp_article (nntp, number, NULL, NULL, &stream); |
463 | } | 480 | } |
464 | 481 | ||
465 | if (status == 0 && stream != NULL) | 482 | if (status == 0 && stream != NULL) |
... | @@ -490,6 +507,59 @@ com_group (char *arg) | ... | @@ -490,6 +507,59 @@ com_group (char *arg) |
490 | return status; | 507 | return status; |
491 | } | 508 | } |
492 | 509 | ||
510 | int com_list (char *arg) | ||
511 | { | ||
512 | int status = EINVAL; | ||
513 | char *keyword = NULL; | ||
514 | |||
515 | if (arg != NULL) | ||
516 | { | ||
517 | char *p = strchr (arg, ' '); | ||
518 | if (p) | ||
519 | { | ||
520 | *p++ = '\0'; | ||
521 | keyword = arg; | ||
522 | arg = p; | ||
523 | } | ||
524 | else | ||
525 | { | ||
526 | keyword = arg; | ||
527 | } | ||
528 | } | ||
529 | else | ||
530 | keyword = arg; | ||
531 | |||
532 | if (keyword == NULL || *keyword == '\0') | ||
533 | { | ||
534 | status = com_list_active (arg); | ||
535 | } | ||
536 | else if (strncasecmp (keyword, "ACTIVE.TIMES", 12) == 0) | ||
537 | { | ||
538 | status = com_list_active_times (arg); | ||
539 | } | ||
540 | else if (strncasecmp (keyword, "ACTIVE", 6) == 0) | ||
541 | { | ||
542 | status = com_list_active (arg); | ||
543 | } | ||
544 | else if (strncasecmp (keyword, "EXTENSIONS", 10) == 0) | ||
545 | { | ||
546 | status = com_list_extensions (arg); | ||
547 | } | ||
548 | else if (strncasecmp (keyword, "DISTRIBUTIONS", 13) == 0) | ||
549 | { | ||
550 | status = com_list_distributions (arg); | ||
551 | } | ||
552 | else if (strncasecmp (keyword, "DISTRIB.PATS", 12) == 0) | ||
553 | { | ||
554 | status = com_list_distrib_pats (arg); | ||
555 | } | ||
556 | else if (strncasecmp (keyword, "NEWSGROUPS", 10) == 0) | ||
557 | { | ||
558 | status = com_list_newsgroups (arg); | ||
559 | } | ||
560 | return status; | ||
561 | } | ||
562 | |||
493 | int | 563 | int |
494 | com_list_extensions (char *arg ARG_UNUSED) | 564 | com_list_extensions (char *arg ARG_UNUSED) |
495 | { | 565 | { |
... | @@ -500,12 +570,13 @@ com_list_extensions (char *arg ARG_UNUSED) | ... | @@ -500,12 +570,13 @@ com_list_extensions (char *arg ARG_UNUSED) |
500 | { | 570 | { |
501 | iterator_t iterator = NULL; | 571 | iterator_t iterator = NULL; |
502 | list_get_iterator (list, &iterator); | 572 | list_get_iterator (list, &iterator); |
573 | printf ("List Extension:\n"); | ||
503 | for (iterator_first (iterator); | 574 | for (iterator_first (iterator); |
504 | !iterator_is_done (iterator); iterator_next (iterator)) | 575 | !iterator_is_done (iterator); iterator_next (iterator)) |
505 | { | 576 | { |
506 | char *extension = NULL; | 577 | char *extension = NULL; |
507 | iterator_current (iterator, (void **) &extension); | 578 | iterator_current (iterator, (void **) &extension); |
508 | printf ("Extension: %s\n", (extension) ? extension : ""); | 579 | printf (" %s\n", extension); |
509 | } | 580 | } |
510 | iterator_destroy (&iterator); | 581 | iterator_destroy (&iterator); |
511 | list_destroy (&list); | 582 | list_destroy (&list); |
... | @@ -513,7 +584,206 @@ com_list_extensions (char *arg ARG_UNUSED) | ... | @@ -513,7 +584,206 @@ com_list_extensions (char *arg ARG_UNUSED) |
513 | return status; | 584 | return status; |
514 | } | 585 | } |
515 | 586 | ||
516 | int com_last (char *arg ARG_UNUSED) | 587 | int |
588 | com_list_active (char *arg) | ||
589 | { | ||
590 | list_t list = NULL; | ||
591 | |||
592 | int status = mu_nntp_list_active (nntp, arg, &list); | ||
593 | |||
594 | if (status == 0) | ||
595 | { | ||
596 | iterator_t iterator = NULL; | ||
597 | list_get_iterator (list, &iterator); | ||
598 | printf ("List Active:\n"); | ||
599 | for (iterator_first (iterator); | ||
600 | !iterator_is_done (iterator); iterator_next (iterator)) | ||
601 | { | ||
602 | char *buffer = NULL; | ||
603 | char *group = NULL; | ||
604 | unsigned long high; | ||
605 | unsigned long low; | ||
606 | char stat; | ||
607 | iterator_current (iterator, (void **) &buffer); | ||
608 | mu_nntp_parse_list_active (buffer, &group, &high, &low, &stat); | ||
609 | if (group) | ||
610 | { | ||
611 | printf (" group(%s)", group); | ||
612 | free (group); | ||
613 | } | ||
614 | printf (" high(%ld) low(%ld) status(%c)\n", high, low, stat); | ||
615 | } | ||
616 | iterator_destroy (&iterator); | ||
617 | list_destroy (&list); | ||
618 | } | ||
619 | return status; | ||
620 | } | ||
621 | |||
622 | int | ||
623 | com_list_active_times (char *arg) | ||
624 | { | ||
625 | list_t list = NULL; | ||
626 | int status = mu_nntp_list_active_times (nntp, arg, &list); | ||
627 | |||
628 | if (status == 0) | ||
629 | { | ||
630 | iterator_t iterator = NULL; | ||
631 | list_get_iterator (list, &iterator); | ||
632 | printf ("List Active.Times:\n"); | ||
633 | for (iterator_first (iterator); | ||
634 | !iterator_is_done (iterator); iterator_next (iterator)) | ||
635 | { | ||
636 | char *buffer = NULL; | ||
637 | char *group = NULL; | ||
638 | char *creator = NULL; | ||
639 | unsigned long time = 0; | ||
640 | iterator_current (iterator, (void **) &buffer); | ||
641 | mu_nntp_parse_list_active_times (buffer, &group, &time, &creator); | ||
642 | if (group) | ||
643 | { | ||
644 | printf (" group(%s)", group); | ||
645 | free (group); | ||
646 | } | ||
647 | if (time) | ||
648 | { | ||
649 | char *p = ctime((time_t *)&time); | ||
650 | char *buf = strdup (p); | ||
651 | p = strchr (buf, '\n'); | ||
652 | if (p) | ||
653 | { | ||
654 | buf[p - buf] = '\0'; | ||
655 | } | ||
656 | printf (" times(%s)", buf); | ||
657 | free (buf); | ||
658 | } | ||
659 | if (creator) | ||
660 | { | ||
661 | printf (" creator(%s)", creator); | ||
662 | free (creator); | ||
663 | } | ||
664 | printf ("\n"); | ||
665 | } | ||
666 | iterator_destroy (&iterator); | ||
667 | list_destroy (&list); | ||
668 | } | ||
669 | return status; | ||
670 | } | ||
671 | |||
672 | int | ||
673 | com_list_distributions (char *arg ARG_UNUSED) | ||
674 | { | ||
675 | list_t list = NULL; | ||
676 | int status = mu_nntp_list_distributions (nntp, arg, &list); | ||
677 | |||
678 | if (status == 0) | ||
679 | { | ||
680 | iterator_t iterator = NULL; | ||
681 | list_get_iterator (list, &iterator); | ||
682 | printf ("List Distributions:\n"); | ||
683 | for (iterator_first (iterator); | ||
684 | !iterator_is_done (iterator); iterator_next (iterator)) | ||
685 | { | ||
686 | char *buffer = NULL; | ||
687 | char *key = NULL; | ||
688 | char *value = NULL; | ||
689 | iterator_current (iterator, (void **) &buffer); | ||
690 | mu_nntp_parse_list_distributions (buffer, &key, &value); | ||
691 | if (key) | ||
692 | { | ||
693 | printf (" %s", key); | ||
694 | free (key); | ||
695 | } | ||
696 | if (value) | ||
697 | { | ||
698 | printf (": %s", value); | ||
699 | free (value); | ||
700 | } | ||
701 | printf ("\n"); | ||
702 | } | ||
703 | iterator_destroy (&iterator); | ||
704 | list_destroy (&list); | ||
705 | } | ||
706 | return status; | ||
707 | } | ||
708 | |||
709 | int | ||
710 | com_list_distrib_pats (char *arg ARG_UNUSED) | ||
711 | { | ||
712 | list_t list = NULL; | ||
713 | int status = mu_nntp_list_distrib_pats (nntp, &list); | ||
714 | |||
715 | if (status == 0) | ||
716 | { | ||
717 | iterator_t iterator = NULL; | ||
718 | list_get_iterator (list, &iterator); | ||
719 | printf ("List Distrib Pats:\n"); | ||
720 | for (iterator_first (iterator); | ||
721 | !iterator_is_done (iterator); iterator_next (iterator)) | ||
722 | { | ||
723 | char *buffer = NULL; | ||
724 | unsigned long weight = 0; | ||
725 | char *wildmat = NULL; | ||
726 | char *distrib = NULL; | ||
727 | iterator_current (iterator, (void **) &buffer); | ||
728 | mu_nntp_parse_list_distrib_pats (buffer, &weight, &wildmat, &distrib); | ||
729 | printf (" weight(%ld)", weight); | ||
730 | if (wildmat) | ||
731 | { | ||
732 | printf (":%s", wildmat); | ||
733 | free (wildmat); | ||
734 | } | ||
735 | if (distrib) | ||
736 | { | ||
737 | printf (":%s", distrib); | ||
738 | free (distrib); | ||
739 | } | ||
740 | printf ("\n"); | ||
741 | } | ||
742 | iterator_destroy (&iterator); | ||
743 | list_destroy (&list); | ||
744 | } | ||
745 | return status; | ||
746 | } | ||
747 | |||
748 | int | ||
749 | com_list_newsgroups (char *arg) | ||
750 | { | ||
751 | list_t list = NULL; | ||
752 | int status = mu_nntp_list_newsgroups (nntp, arg, &list); | ||
753 | |||
754 | if (status == 0) | ||
755 | { | ||
756 | iterator_t iterator = NULL; | ||
757 | list_get_iterator (list, &iterator); | ||
758 | printf ("Newsgroups:\n"); | ||
759 | for (iterator_first (iterator); | ||
760 | !iterator_is_done (iterator); iterator_next (iterator)) | ||
761 | { | ||
762 | char *buffer = NULL; | ||
763 | char *group = NULL; | ||
764 | char *desc = NULL; | ||
765 | iterator_current (iterator, (void **) &buffer); | ||
766 | mu_nntp_parse_list_newsgroups (buffer, &group, &desc); | ||
767 | if (group) | ||
768 | { | ||
769 | printf (" %s", group); | ||
770 | free (group); | ||
771 | } | ||
772 | if (desc) | ||
773 | { | ||
774 | printf (":%s", desc); | ||
775 | free (desc); | ||
776 | } | ||
777 | printf ("\n"); | ||
778 | } | ||
779 | iterator_destroy (&iterator); | ||
780 | list_destroy (&list); | ||
781 | } | ||
782 | return status; | ||
783 | } | ||
784 | |||
785 | int | ||
786 | com_last (char *arg ARG_UNUSED) | ||
517 | { | 787 | { |
518 | char *mid = NULL; | 788 | char *mid = NULL; |
519 | unsigned long number = 0; | 789 | unsigned long number = 0; |
... | @@ -527,7 +797,8 @@ int com_last (char *arg ARG_UNUSED) | ... | @@ -527,7 +797,8 @@ int com_last (char *arg ARG_UNUSED) |
527 | return status; | 797 | return status; |
528 | } | 798 | } |
529 | 799 | ||
530 | int com_next (char *arg ARG_UNUSED) | 800 | int |
801 | com_next (char *arg ARG_UNUSED) | ||
531 | { | 802 | { |
532 | char *mid = NULL; | 803 | char *mid = NULL; |
533 | unsigned long number = 0; | 804 | unsigned long number = 0; |
... | @@ -542,6 +813,114 @@ int com_next (char *arg ARG_UNUSED) | ... | @@ -542,6 +813,114 @@ int com_next (char *arg ARG_UNUSED) |
542 | } | 813 | } |
543 | 814 | ||
544 | int | 815 | int |
816 | com_newgroups (char *arg) | ||
817 | { | ||
818 | list_t list = NULL; | ||
819 | struct tm stime; | ||
820 | int year, month, day, hour, min, sec, is_gmt; | ||
821 | year = month = day = hour = min = sec = is_gmt = 0; | ||
822 | |||
823 | if (arg != NULL && *arg != '\0') | ||
824 | { | ||
825 | char gmt[4]; | ||
826 | memset (gmt, 0, 4); | ||
827 | sscanf (arg, "%4d%2d%2d %2d%2d%2d %3s", &year, &month, &day, &hour, &min, &sec, gmt); | ||
828 | is_gmt = strncasecmp ("GMT", gmt, 3) == 0; | ||
829 | } | ||
830 | |||
831 | /* If nothing defined take the current time. */ | ||
832 | if (year == 0) | ||
833 | { | ||
834 | time_t now = time (NULL); | ||
835 | struct tm *stime = localtime (&now); | ||
836 | sec = stime->tm_sec; /* seconds */ | ||
837 | min = stime->tm_min; /* minutes */ | ||
838 | hour = stime->tm_hour; /* hours */ | ||
839 | day = stime->tm_mday; /* day of the month */ | ||
840 | month = stime->tm_mon; /* month */ | ||
841 | year = stime->tm_year + 1900; /* year */ | ||
842 | } | ||
843 | |||
844 | int status = mu_nntp_newgroups (nntp, year, month, day, hour, min, sec, is_gmt, &list); | ||
845 | if (status == 0) | ||
846 | { | ||
847 | iterator_t iterator = NULL; | ||
848 | list_get_iterator (list, &iterator); | ||
849 | printf ("New Groups:\n"); | ||
850 | for (iterator_first (iterator); | ||
851 | !iterator_is_done (iterator); iterator_next (iterator)) | ||
852 | { | ||
853 | char *buffer = NULL; | ||
854 | char *group = NULL; | ||
855 | unsigned long high = 0; | ||
856 | unsigned long low = 0; | ||
857 | char stat = 0; | ||
858 | iterator_current (iterator, (void **) &buffer); | ||
859 | mu_nntp_parse_newgroups (buffer, &group, &high, &low, &stat); | ||
860 | if (group) | ||
861 | { | ||
862 | printf (" group(%s)", group); | ||
863 | free (group); | ||
864 | } | ||
865 | printf (" hig(%d) low(%d) status(%c)\n", high, low, stat); | ||
866 | } | ||
867 | iterator_destroy (&iterator); | ||
868 | list_destroy (&list); | ||
869 | } | ||
870 | return status; | ||
871 | } | ||
872 | |||
873 | int | ||
874 | com_newnews (char *arg) | ||
875 | { | ||
876 | list_t list = NULL; | ||
877 | struct tm stime; | ||
878 | char *wildmat; | ||
879 | char gmt[4]; | ||
880 | int year, month, day, hour, min, sec, is_gmt; | ||
881 | |||
882 | if (!valid_argument ("newnews", arg)) | ||
883 | return EINVAL; | ||
884 | |||
885 | year = month = day = hour = min = sec = is_gmt = 0; | ||
886 | memset (gmt, 0, 4); | ||
887 | |||
888 | wildmat = calloc (1, 512); | ||
889 | sscanf (arg, "%511s %4d%2d%2d %2d%2d%2d %3s", wildmat, &year, &month, &day, &hour, &min, &sec, gmt); | ||
890 | is_gmt = strncasecmp ("GMT", gmt, 3) == 0; | ||
891 | |||
892 | if (year == 0) | ||
893 | { | ||
894 | time_t now = time (NULL); | ||
895 | struct tm *stime = localtime (&now); | ||
896 | sec = stime->tm_sec; /* seconds */ | ||
897 | min = stime->tm_min; /* minutes */ | ||
898 | hour = stime->tm_hour; /* hours */ | ||
899 | day = stime->tm_mday; /* day of the month */ | ||
900 | month = stime->tm_mon; /* month */ | ||
901 | year = stime->tm_year + 1900; /* year */ | ||
902 | } | ||
903 | |||
904 | int status = mu_nntp_newnews (nntp, wildmat, year, month, day, hour, min, sec, is_gmt, &list); | ||
905 | if (status == 0) | ||
906 | { | ||
907 | iterator_t iterator = NULL; | ||
908 | list_get_iterator (list, &iterator); | ||
909 | printf ("New News:\n"); | ||
910 | for (iterator_first (iterator); | ||
911 | !iterator_is_done (iterator); iterator_next (iterator)) | ||
912 | { | ||
913 | char *mid = NULL; | ||
914 | iterator_current (iterator, (void **) &mid); | ||
915 | printf (" %s\n", mid); | ||
916 | } | ||
917 | iterator_destroy (&iterator); | ||
918 | list_destroy (&list); | ||
919 | } | ||
920 | return status; | ||
921 | } | ||
922 | |||
923 | int | ||
545 | com_stat (char *arg) | 924 | com_stat (char *arg) |
546 | { | 925 | { |
547 | char *mid = NULL; | 926 | char *mid = NULL; |
... | @@ -567,7 +946,8 @@ com_stat (char *arg) | ... | @@ -567,7 +946,8 @@ com_stat (char *arg) |
567 | return status; | 946 | return status; |
568 | } | 947 | } |
569 | 948 | ||
570 | int com_date (char *arg ARG_UNUSED) | 949 | int |
950 | com_date (char *arg ARG_UNUSED) | ||
571 | { | 951 | { |
572 | unsigned int year, month, day, hour, min, sec; | 952 | unsigned int year, month, day, hour, min, sec; |
573 | int status; | 953 | int status; |
... | @@ -575,7 +955,39 @@ int com_date (char *arg ARG_UNUSED) | ... | @@ -575,7 +955,39 @@ int com_date (char *arg ARG_UNUSED) |
575 | status = mu_nntp_date (nntp, &year, &month, &day, &hour, &min, &sec); | 955 | status = mu_nntp_date (nntp, &year, &month, &day, &hour, &min, &sec); |
576 | if (status == 0) | 956 | if (status == 0) |
577 | { | 957 | { |
578 | fprintf (stdout, "%d %d %d %d %d %d\n", year, month, day, hour, min, sec); | 958 | fprintf (stdout, "date: year(%d) month(%d) day(%d) hour(%d) min(%d) sec(%d)\n", year, month, day, hour, min, sec); |
959 | } | ||
960 | return status; | ||
961 | } | ||
962 | |||
963 | int | ||
964 | com_post (char *arg) | ||
965 | { | ||
966 | fprintf (stderr, "Not implemented\n"); | ||
967 | return 0; | ||
968 | } | ||
969 | |||
970 | int | ||
971 | com_ihave (char *arg) | ||
972 | { | ||
973 | fprintf (stderr, "Not implemented\n"); | ||
974 | return 0; | ||
975 | } | ||
976 | |||
977 | int | ||
978 | com_help (char *arg ARG_UNUSED) | ||
979 | { | ||
980 | stream_t stream = NULL; | ||
981 | int status; | ||
982 | |||
983 | status = mu_nntp_help (nntp, &stream); | ||
984 | if (status == 0 && stream != NULL) | ||
985 | { | ||
986 | size_t n = 0; | ||
987 | char buf[128]; | ||
988 | while ((stream_readline (stream, buf, sizeof buf, 0, &n) == 0) && n) | ||
989 | printf ("%s", buf); | ||
990 | stream_destroy (&stream, NULL); | ||
579 | } | 991 | } |
580 | return status; | 992 | return status; |
581 | } | 993 | } |
... | @@ -583,7 +995,7 @@ int com_date (char *arg ARG_UNUSED) | ... | @@ -583,7 +995,7 @@ int com_date (char *arg ARG_UNUSED) |
583 | /* Print out help for ARG, or for all of the commands if ARG is | 995 | /* Print out help for ARG, or for all of the commands if ARG is |
584 | not present. */ | 996 | not present. */ |
585 | int | 997 | int |
586 | com_help (char *arg) | 998 | com_info (char *arg) |
587 | { | 999 | { |
588 | int i; | 1000 | int i; |
589 | int printed = 0; | 1001 | int printed = 0; |
... | @@ -624,11 +1036,16 @@ int | ... | @@ -624,11 +1036,16 @@ int |
624 | com_connect (char *arg) | 1036 | com_connect (char *arg) |
625 | { | 1037 | { |
626 | char host[256]; | 1038 | char host[256]; |
627 | int port = 110; | 1039 | int port = 119; |
628 | int status; | 1040 | int status; |
629 | if (!valid_argument ("connect", arg)) | 1041 | |
630 | return 1; | ||
631 | *host = '\0'; | 1042 | *host = '\0'; |
1043 | |||
1044 | /* Try with the environment. */ | ||
1045 | if (arg == NULL || *arg == '\0') | ||
1046 | arg = getenv ("NNTPSERVER"); | ||
1047 | if (!valid_argument ("connect", arg)) | ||
1048 | return EINVAL; | ||
632 | sscanf (arg, "%256s %d", host, &port); | 1049 | sscanf (arg, "%256s %d", host, &port); |
633 | if (!valid_argument ("connect", host)) | 1050 | if (!valid_argument ("connect", host)) |
634 | return EINVAL; | 1051 | return EINVAL; |
... | @@ -640,7 +1057,7 @@ com_connect (char *arg) | ... | @@ -640,7 +1057,7 @@ com_connect (char *arg) |
640 | stream_t tcp; | 1057 | stream_t tcp; |
641 | 1058 | ||
642 | if (verbose) | 1059 | if (verbose) |
643 | com_verbose ("verbose on"); | 1060 | com_verbose ("on"); |
644 | status = | 1061 | status = |
645 | tcp_stream_create (&tcp, host, port, | 1062 | tcp_stream_create (&tcp, host, port, |
646 | MU_STREAM_READ | MU_STREAM_NO_CHECK); | 1063 | MU_STREAM_READ | MU_STREAM_NO_CHECK); |
... | @@ -662,7 +1079,7 @@ com_connect (char *arg) | ... | @@ -662,7 +1079,7 @@ com_connect (char *arg) |
662 | } | 1079 | } |
663 | 1080 | ||
664 | int | 1081 | int |
665 | com_disconnect (char *arg) | 1082 | com_disconnect (char *arg ARG_UNUSED) |
666 | { | 1083 | { |
667 | (void) arg; | 1084 | (void) arg; |
668 | if (nntp) | 1085 | if (nntp) |
... | @@ -677,11 +1094,12 @@ com_disconnect (char *arg) | ... | @@ -677,11 +1094,12 @@ com_disconnect (char *arg) |
677 | int | 1094 | int |
678 | com_quit (char *arg ARG_UNUSED) | 1095 | com_quit (char *arg ARG_UNUSED) |
679 | { | 1096 | { |
1097 | int status = 0; | ||
680 | if (nntp) | 1098 | if (nntp) |
681 | { | 1099 | { |
682 | if (mu_nntp_quit (nntp) == 0) | 1100 | if (mu_nntp_quit (nntp) == 0) |
683 | { | 1101 | { |
684 | mu_nntp_disconnect (nntp); | 1102 | status = com_disconnect (arg); |
685 | } | 1103 | } |
686 | else | 1104 | else |
687 | { | 1105 | { |
... | @@ -690,7 +1108,7 @@ com_quit (char *arg ARG_UNUSED) | ... | @@ -690,7 +1108,7 @@ com_quit (char *arg ARG_UNUSED) |
690 | } | 1108 | } |
691 | else | 1109 | else |
692 | fprintf (stdout, "Try 'exit' to leave %s\n", progname); | 1110 | fprintf (stdout, "Try 'exit' to leave %s\n", progname); |
693 | return 0; | 1111 | return status; |
694 | } | 1112 | } |
695 | 1113 | ||
696 | int | 1114 | int |
... | @@ -710,7 +1128,7 @@ com_exit (char *arg ARG_UNUSED) | ... | @@ -710,7 +1128,7 @@ com_exit (char *arg ARG_UNUSED) |
710 | int | 1128 | int |
711 | valid_argument (const char *caller, char *arg) | 1129 | valid_argument (const char *caller, char *arg) |
712 | { | 1130 | { |
713 | if (arg == NULL || *arg == '\0' || strchr (arg, ' ') != NULL) | 1131 | if (arg == NULL || *arg == '\0') |
714 | { | 1132 | { |
715 | fprintf (stderr, "%s: Argument required.\n", caller); | 1133 | fprintf (stderr, "%s: Argument required.\n", caller); |
716 | return 0; | 1134 | return 0; | ... | ... |
... | @@ -681,7 +681,7 @@ com_connect (char *arg) | ... | @@ -681,7 +681,7 @@ com_connect (char *arg) |
681 | stream_t tcp; | 681 | stream_t tcp; |
682 | 682 | ||
683 | if (verbose) | 683 | if (verbose) |
684 | com_verbose ("verbose on"); | 684 | com_verbose ("on"); |
685 | status = | 685 | status = |
686 | tcp_stream_create (&tcp, host, port, | 686 | tcp_stream_create (&tcp, host, port, |
687 | MU_STREAM_READ | MU_STREAM_NO_CHECK); | 687 | MU_STREAM_READ | MU_STREAM_NO_CHECK); |
... | @@ -703,7 +703,7 @@ com_connect (char *arg) | ... | @@ -703,7 +703,7 @@ com_connect (char *arg) |
703 | } | 703 | } |
704 | 704 | ||
705 | int | 705 | int |
706 | com_disconnect (char *arg) | 706 | com_disconnect (char *arg ARG_UNUSED) |
707 | { | 707 | { |
708 | (void) arg; | 708 | (void) arg; |
709 | if (pop3) | 709 | if (pop3) |
... | @@ -718,11 +718,12 @@ com_disconnect (char *arg) | ... | @@ -718,11 +718,12 @@ com_disconnect (char *arg) |
718 | int | 718 | int |
719 | com_quit (char *arg ARG_UNUSED) | 719 | com_quit (char *arg ARG_UNUSED) |
720 | { | 720 | { |
721 | int status = 0; | ||
721 | if (pop3) | 722 | if (pop3) |
722 | { | 723 | { |
723 | if (mu_pop3_quit (pop3) == 0) | 724 | if (mu_pop3_quit (pop3) == 0) |
724 | { | 725 | { |
725 | mu_pop3_disconnect (pop3); | 726 | status = com_disconnect (arg); |
726 | } | 727 | } |
727 | else | 728 | else |
728 | { | 729 | { |
... | @@ -731,7 +732,7 @@ com_quit (char *arg ARG_UNUSED) | ... | @@ -731,7 +732,7 @@ com_quit (char *arg ARG_UNUSED) |
731 | } | 732 | } |
732 | else | 733 | else |
733 | fprintf (stdout, "Try 'exit' to leave %s\n", progname); | 734 | fprintf (stdout, "Try 'exit' to leave %s\n", progname); |
734 | return 0; | 735 | return status; |
735 | } | 736 | } |
736 | 737 | ||
737 | int | 738 | int | ... | ... |
-
Please register or sign in to post a comment