Commit 91c4dd4e 91c4dd4eae434f5b957685db3bf16652c530a434 by Alain Magloire

Makefile.am

Add pop3client as a program
pop3client.c :
	check for errors.
1 parent d2bd2cae
...@@ -29,7 +29,8 @@ noinst_PROGRAMS = \ ...@@ -29,7 +29,8 @@ noinst_PROGRAMS = \
29 http\ 29 http\
30 mta\ 30 mta\
31 decode2047\ 31 decode2047\
32 mailcap 32 mailcap \
33 pop3client
33 34
34 moddir=@SIEVE_MODDIR@ 35 moddir=@SIEVE_MODDIR@
35 mod_LTLIBRARIES = numaddr.la 36 mod_LTLIBRARIES = numaddr.la
...@@ -62,6 +63,12 @@ sfrom_LDADD =\ ...@@ -62,6 +63,12 @@ sfrom_LDADD =\
62 ../lib/libmailutils.la\ 63 ../lib/libmailutils.la\
63 @AUTHLIBS@ 64 @AUTHLIBS@
64 65
66 pop3client_LDADD = \
67 ../mailbox/pop/libmu_pop.la\
68 ../mailbox/libmailbox.la\
69 ../lib/libmailutils.la\
70 @AUTHLIBS@ @READLINE_LIBS@
71
65 EXTRA_DIST = comsat.conf dot.biffrc gnu-imap4d.pam gnu-pop3d.pam\ 72 EXTRA_DIST = comsat.conf dot.biffrc gnu-imap4d.pam gnu-pop3d.pam\
66 mailutils.rc reply.scm 73 mailutils.rc reply.scm
67 74
......
...@@ -62,6 +62,7 @@ int com_stat (char *); ...@@ -62,6 +62,7 @@ int com_stat (char *);
62 int com_top (char *); 62 int com_top (char *);
63 int com_uidl (char *); 63 int com_uidl (char *);
64 int com_user (char *); 64 int com_user (char *);
65 int com_verbose (char *);
65 66
66 void initialize_readline (void); 67 void initialize_readline (void);
67 char *stripwhite (char *); 68 char *stripwhite (char *);
...@@ -92,6 +93,7 @@ COMMAND commands[] = { ...@@ -92,6 +93,7 @@ COMMAND commands[] = {
92 { "top", com_top, "Get the header of message: TOP msgno [lines]" }, 93 { "top", com_top, "Get the header of message: TOP msgno [lines]" },
93 { "uidl", com_uidl, "Get the uniq id of message: UIDL [msgno]" }, 94 { "uidl", com_uidl, "Get the uniq id of message: UIDL [msgno]" },
94 { "user", com_user, "send login: USER user" }, 95 { "user", com_user, "send login: USER user" },
96 { "verbose", com_verbose, "Enable Protocol tracing: verbose [on|off]" },
95 { NULL, NULL, NULL } 97 { NULL, NULL, NULL }
96 }; 98 };
97 99
...@@ -101,6 +103,9 @@ char *progname; ...@@ -101,6 +103,9 @@ char *progname;
101 /* Global handle for pop3. */ 103 /* Global handle for pop3. */
102 mu_pop3_t pop3; 104 mu_pop3_t pop3;
103 105
106 /* Flag if verbosity is needed. */
107 int verbose;
108
104 /* When non-zero, this global means the user is done using this program. */ 109 /* When non-zero, this global means the user is done using this program. */
105 int done; 110 int done;
106 111
...@@ -158,8 +163,11 @@ main (int argc, char **argv) ...@@ -158,8 +163,11 @@ main (int argc, char **argv)
158 163
159 if (*s) 164 if (*s)
160 { 165 {
166 int status;
161 add_history (s); 167 add_history (s);
162 execute_line (s); 168 status = execute_line (s);
169 if (status != 0)
170 fprintf (stderr, "Error: %s\n", strerror(status));
163 } 171 }
164 172
165 free (line); 173 free (line);
...@@ -317,23 +325,49 @@ command_generator (const char *text, int state) ...@@ -317,23 +325,49 @@ command_generator (const char *text, int state)
317 } 325 }
318 326
319 int 327 int
328 com_verbose (char *arg)
329 {
330 int status = 0;
331 if (!valid_argument ("verbose", arg))
332 return EINVAL;
333
334 verbose = (strcmp (arg, "on") == 0);
335 if (pop3 != NULL)
336 {
337 if (verbose == 1)
338 {
339 mu_debug_t debug;
340 mu_debug_create (&debug, NULL);
341 mu_debug_set_level (debug, MU_DEBUG_PROT);
342 status = mu_pop3_set_debug (pop3, debug);
343 }
344 else
345 {
346 status = mu_pop3_set_debug (pop3, NULL);
347 }
348 }
349 return status;
350 }
351
352 int
320 com_user (char *arg) 353 com_user (char *arg)
321 { 354 {
322 if (!valid_argument ("user", arg)) 355 if (!valid_argument ("user", arg))
323 return 1; 356 return EINVAL;
324 return mu_pop3_user (pop3, arg); 357 return mu_pop3_user (pop3, arg);
325 } 358 }
359
326 int 360 int
327 com_apop (char *arg) 361 com_apop (char *arg)
328 { 362 {
329 char *user, *digest; 363 char *user, *digest;
330 364
331 if (!valid_argument ("apop", arg)) 365 if (!valid_argument ("apop", arg))
332 return 1; 366 return EINVAL;
333 user = strtok (arg, " "); 367 user = strtok (arg, " ");
334 digest = strtok (NULL, " "); 368 digest = strtok (NULL, " ");
335 if (!valid_argument ("apop", user) || !valid_argument ("apop", digest)) 369 if (!valid_argument ("apop", user) || !valid_argument ("apop", digest))
336 return 1; 370 return EINVAL;
337 return mu_pop3_apop (pop3, user, digest); 371 return mu_pop3_apop (pop3, user, digest);
338 } 372 }
339 373
...@@ -364,10 +398,11 @@ com_capa (char *arg) ...@@ -364,10 +398,11 @@ com_capa (char *arg)
364 int 398 int
365 com_uidl (char *arg) 399 com_uidl (char *arg)
366 { 400 {
401 int status = 0;
367 if (arg == NULL || *arg == '\0') 402 if (arg == NULL || *arg == '\0')
368 { 403 {
369 list_t list = NULL; 404 list_t list = NULL;
370 int status = mu_pop3_uidl_all (pop3, &list); 405 status = mu_pop3_uidl_all (pop3, &list);
371 if (status == 0) 406 if (status == 0)
372 { 407 {
373 iterator_t uidl_iterator = NULL; 408 iterator_t uidl_iterator = NULL;
...@@ -388,20 +423,22 @@ com_uidl (char *arg) ...@@ -388,20 +423,22 @@ com_uidl (char *arg)
388 { 423 {
389 char *uidl = NULL; 424 char *uidl = NULL;
390 unsigned int msgno = strtoul (arg, NULL, 10); 425 unsigned int msgno = strtoul (arg, NULL, 10);
391 if (mu_pop3_uidl (pop3, msgno, &uidl) == 0) 426 status = mu_pop3_uidl (pop3, msgno, &uidl);
427 if (status == 0)
392 printf ("Msg: %d UIDL: %s\n", msgno, (uidl) ? uidl : ""); 428 printf ("Msg: %d UIDL: %s\n", msgno, (uidl) ? uidl : "");
393 free (uidl); 429 free (uidl);
394 } 430 }
395 return 0; 431 return status;
396 } 432 }
397 433
398 int 434 int
399 com_list (char *arg) 435 com_list (char *arg)
400 { 436 {
437 int status = 0;
401 if (arg == NULL || *arg == '\0') 438 if (arg == NULL || *arg == '\0')
402 { 439 {
403 list_t list = NULL; 440 list_t list = NULL;
404 int status = mu_pop3_list_all (pop3, &list); 441 status = mu_pop3_list_all (pop3, &list);
405 if (status == 0) 442 if (status == 0)
406 { 443 {
407 iterator_t list_iterator; 444 iterator_t list_iterator;
...@@ -422,10 +459,11 @@ com_list (char *arg) ...@@ -422,10 +459,11 @@ com_list (char *arg)
422 { 459 {
423 size_t size = 0; 460 size_t size = 0;
424 unsigned int msgno = strtoul (arg, NULL, 10); 461 unsigned int msgno = strtoul (arg, NULL, 10);
425 if (mu_pop3_list (pop3, msgno, &size) == 0) 462 status = mu_pop3_list (pop3, msgno, &size);
463 if (status == 0)
426 printf ("Msg: %d Size: %d\n", msgno, size); 464 printf ("Msg: %d Size: %d\n", msgno, size);
427 } 465 }
428 return 0; 466 return status;
429 } 467 }
430 468
431 int 469 int
...@@ -452,8 +490,7 @@ echo_on(struct termios *stored_settings) ...@@ -452,8 +490,7 @@ echo_on(struct termios *stored_settings)
452 } 490 }
453 491
454 int 492 int
455 com_pass (arg) 493 com_pass (char *arg)
456 char *arg;
457 { 494 {
458 char pass[256]; 495 char pass[256];
459 if (!arg || *arg == '\0') 496 if (!arg || *arg == '\0')
...@@ -477,12 +514,13 @@ int ...@@ -477,12 +514,13 @@ int
477 com_stat (char *arg) 514 com_stat (char *arg)
478 { 515 {
479 unsigned count, size; 516 unsigned count, size;
517 int status = 0;
480 518
481 (void)arg; 519 (void)arg;
482 count = size = 0; 520 count = size = 0;
483 mu_pop3_stat (pop3, &count, &size); 521 status = mu_pop3_stat (pop3, &count, &size);
484 fprintf (stdout, "Mesgs: %d Size %d\n", count, size); 522 fprintf (stdout, "Mesgs: %d Size %d\n", count, size);
485 return 0; 523 return status;
486 } 524 }
487 525
488 int 526 int
...@@ -491,7 +529,7 @@ com_dele (arg) ...@@ -491,7 +529,7 @@ com_dele (arg)
491 { 529 {
492 unsigned msgno; 530 unsigned msgno;
493 if (!valid_argument ("dele", arg)) 531 if (!valid_argument ("dele", arg))
494 return 1; 532 return EINVAL;
495 msgno = strtoul (arg, NULL, 10); 533 msgno = strtoul (arg, NULL, 10);
496 return mu_pop3_dele (pop3, msgno); 534 return mu_pop3_dele (pop3, msgno);
497 } 535 }
...@@ -553,7 +591,7 @@ com_top (char *arg) ...@@ -553,7 +591,7 @@ com_top (char *arg)
553 int status; 591 int status;
554 592
555 if (!valid_argument ("top", arg)) 593 if (!valid_argument ("top", arg))
556 return 1; 594 return EINVAL;
557 595
558 space = strchr (arg, ' '); 596 space = strchr (arg, ' ');
559 if (space) 597 if (space)
...@@ -575,7 +613,7 @@ com_top (char *arg) ...@@ -575,7 +613,7 @@ com_top (char *arg)
575 printf ("%s", buf); 613 printf ("%s", buf);
576 stream_destroy (&stream, NULL); 614 stream_destroy (&stream, NULL);
577 } 615 }
578 return 0; 616 return status;
579 } 617 }
580 618
581 int 619 int
...@@ -586,7 +624,7 @@ com_retr (char *arg) ...@@ -586,7 +624,7 @@ com_retr (char *arg)
586 int status; 624 int status;
587 625
588 if (!valid_argument ("retr", arg)) 626 if (!valid_argument ("retr", arg))
589 return 1; 627 return EINVAL;
590 628
591 msgno = strtoul (arg, NULL, 10); 629 msgno = strtoul (arg, NULL, 10);
592 status = mu_pop3_retr (pop3, msgno, &stream); 630 status = mu_pop3_retr (pop3, msgno, &stream);
...@@ -599,13 +637,7 @@ com_retr (char *arg) ...@@ -599,13 +637,7 @@ com_retr (char *arg)
599 printf ("%s", buf); 637 printf ("%s", buf);
600 stream_destroy (&stream, NULL); 638 stream_destroy (&stream, NULL);
601 } 639 }
602 return 0; 640 return status;
603 }
604
605 void
606 com_debug (const char *buffer)
607 {
608 printf ("%s", buffer);
609 } 641 }
610 642
611 int 643 int
...@@ -619,28 +651,32 @@ com_connect (char *arg) ...@@ -619,28 +651,32 @@ com_connect (char *arg)
619 *host = '\0'; 651 *host = '\0';
620 sscanf (arg, "%256s %d", host, &port); 652 sscanf (arg, "%256s %d", host, &port);
621 if (!valid_argument ("connect", host)) 653 if (!valid_argument ("connect", host))
622 return 1; 654 return EINVAL;
623 if (pop3) 655 if (pop3)
624 com_disconnect (NULL); 656 com_disconnect (NULL);
625 status = mu_pop3_create (&pop3); 657 status = mu_pop3_create (&pop3);
626 if (status == 0) 658 if (status == 0)
627 { 659 {
628 //mu_debug_t debug;
629 stream_t tcp; 660 stream_t tcp;
630 mu_pop3_set_debug (pop3, com_debug); 661
631 //mu_debug_set_level (debug, MU_DEBUG_PROT); 662 if (verbose)
632 //mu_debug_destroy (&debug); 663 com_verbose ("verbose on");
633 status = tcp_stream_create (&tcp, host, port, MU_STREAM_READ | MU_STREAM_NO_CHECK); 664 status = tcp_stream_create (&tcp, host, port, MU_STREAM_READ | MU_STREAM_NO_CHECK);
634 if (status == 0) 665 if (status == 0)
635 { 666 {
636 mu_pop3_set_carrier (pop3, tcp); 667 mu_pop3_set_carrier (pop3, tcp);
637 status = mu_pop3_connect (pop3); 668 status = mu_pop3_connect (pop3);
638 } 669 }
670 else
671 {
672 mu_pop3_destroy (&pop3);
673 pop3 = NULL;
674 }
639 } 675 }
640 676
641 if (status != 0) 677 if (status != 0)
642 fprintf (stderr, "Failed to create pop3: %s\n", strerror (status)); 678 fprintf (stderr, "Failed to create pop3: %s\n", strerror (status));
643 return 0; 679 return status;
644 } 680 }
645 681
646 int 682 int
......