Commit 5c987eb1 5c987eb1e85c30c4eefef7fe8dfda57258bda78d by Sam Roberts

First crack at including wicket_t's ticket, not tested.

1 parent db7d2457
...@@ -63,7 +63,8 @@ mu_copy_debug_level (const mailbox_t from, mailbox_t to) ...@@ -63,7 +63,8 @@ mu_copy_debug_level (const mailbox_t from, mailbox_t to)
63 } 63 }
64 64
65 int 65 int
66 mu_save_to (const char *toname, message_t mesg, const char **errmsg) 66 mu_save_to (const char *toname, message_t mesg,
67 ticket_t ticket, const char **errmsg)
67 { 68 {
68 int res = 0; 69 int res = 0;
69 mailbox_t to = 0; 70 mailbox_t to = 0;
...@@ -74,6 +75,29 @@ mu_save_to (const char *toname, message_t mesg, const char **errmsg) ...@@ -74,6 +75,29 @@ mu_save_to (const char *toname, message_t mesg, const char **errmsg)
74 if (res == ENOENT) 75 if (res == ENOENT)
75 *errmsg = "no handler for this type of mailbox"; 76 *errmsg = "no handler for this type of mailbox";
76 77
78 if (ticket)
79 {
80 folder_t folder = NULL;
81 authority_t auth = NULL;
82
83 if (!res)
84 {
85 *errmsg = "mailbox_get_folder";
86 res = mailbox_get_folder (to, &folder);
87 }
88
89 if (!res)
90 {
91 *errmsg = "folder_get_authority";
92 res = folder_get_authority (folder, &auth);
93 }
94
95 if (!res)
96 {
97 *errmsg = "authority_set_ticket";
98 res = authority_set_ticket (auth, ticket);
99 }
100 }
77 if (!res) 101 if (!res)
78 { 102 {
79 if (message_get_mailbox (mesg, &from) == 0) 103 if (message_get_mailbox (mesg, &from) == 0)
...@@ -101,6 +125,9 @@ mu_save_to (const char *toname, message_t mesg, const char **errmsg) ...@@ -101,6 +125,9 @@ mu_save_to (const char *toname, message_t mesg, const char **errmsg)
101 } 125 }
102 mailbox_destroy (&to); 126 mailbox_destroy (&to);
103 127
128 if(res == 0)
129 *errmsg = 0;
130
104 return res; 131 return res;
105 } 132 }
106 133
...@@ -135,7 +162,7 @@ sv_errno (int rc) ...@@ -135,7 +162,7 @@ sv_errno (int rc)
135 162
136 /** sieve context structures 163 /** sieve context structures
137 164
138 The object relationship diagram is this, with the names in [] 165 The object relationship diagram is this, with the names in ""
139 being the argument name when the context's are provided as 166 being the argument name when the context's are provided as
140 arguments to callback functions. 167 arguments to callback functions.
141 168
...@@ -159,15 +186,19 @@ arguments to callback functions. ...@@ -159,15 +186,19 @@ arguments to callback functions.
159 typedef struct sv_interp_ctx_t 186 typedef struct sv_interp_ctx_t
160 { 187 {
161 /* cmd line options */ 188 /* cmd line options */
162 int opt_no_actions; 189 int opt_no_actions;
163 int opt_verbose; 190 int opt_verbose;
164 int opt_no_run; 191 int opt_no_run;
165 int opt_watch; 192 int opt_watch;
166 char*opt_mbox; 193 char* opt_mbox;
167 char*opt_script; 194 char* opt_tickets;
195 char* opt_script;
168 196
169 int print_mask; 197 int print_mask;
170 FILE*print_stream; 198 FILE* print_stream;
199
200 /* Ticket for use by mailbox URLs for implicit authentication. */
201 ticket_t ticket;
171 202
172 /* mailutils debug handle, we need to destroy it */ 203 /* mailutils debug handle, we need to destroy it */
173 mu_debug_t debug; 204 mu_debug_t debug;
...@@ -446,7 +477,7 @@ sv_fileinto (void *ac, void *ic, void *sc, void *mc, const char **errmsg) ...@@ -446,7 +477,7 @@ sv_fileinto (void *ac, void *ic, void *sc, void *mc, const char **errmsg)
446 477
447 if (!i->opt_no_actions) 478 if (!i->opt_no_actions)
448 { 479 {
449 res = mu_save_to (a->mailbox, m->msg, errmsg); 480 res = mu_save_to (a->mailbox, m->msg, i->ticket, errmsg);
450 } 481 }
451 if (res && !errmsg) 482 if (res && !errmsg)
452 *errmsg = strerror (res); 483 *errmsg = strerror (res);
...@@ -652,26 +683,30 @@ sieve_register_mailutils (sieve_interp_t * i) ...@@ -652,26 +683,30 @@ sieve_register_mailutils (sieve_interp_t * i)
652 return res; 683 return res;
653 } 684 }
654 685
655 const char USAGE[] = "usage: sieve [-hnvcd] [-D mask] [-f mbox] script\n"; 686 const char USAGE[] =
687 "usage: sieve [-hnvcd] [-D mask] [-f mbox] [-t tickets] script\n";
656 688
657 const char HELP[] = 689 const char HELP[] =
658 " -h print this helpful message and exit.\n" 690 " -h print this helpful message and exit.\n"
659 " -n no actions taken, implies -v.\n" 691 " -n no actions taken, implies -v.\n"
660 " -v verbose, print actions taken, more v's, more verbose.\n" 692 " -v verbose, print actions taken, more v's, more verbose.\n"
661 " -c compile script but don't run it against an mbox.\n" 693 " -c compile script but don't run it against an mbox.\n"
694 " -f the mbox to sieve, defaults to the users spool file.\n"
695 " -t a ticket file to use for authentication to mailboxes.\n"
662 " -d daemon mode, sieve mbox, then go into background and sieve.\n" 696 " -d daemon mode, sieve mbox, then go into background and sieve.\n"
663 " new message as they are delivered to mbox.\n" 697 " new message as they are delivered to mbox.\n"
664 " -D debug mask, see source for meaning (sorry).\n" 698 " -D debug mask, see source for meaning (sorry).\n"
665 " -f the mbox to sieve, defaults to the users spool file.\n"; 699 ;
666 700
667 int 701 int
668 main (int argc, char *argv[]) 702 main (int argc, char *argv[])
669 { 703 {
670 list_t bookie = 0; 704 list_t bookie = 0;
671 mailbox_t mbox = 0; 705 mailbox_t mbox = 0;
706 wicket_t wicket = 0;
672 707
673 sieve_interp_t *interp; 708 sieve_interp_t *interp = 0;
674 sieve_script_t *script; 709 sieve_script_t *script = 0;
675 710
676 sv_interp_ctx_t ic = { 0, }; 711 sv_interp_ctx_t ic = { 0, };
677 sv_script_ctx_t sc = { 0, }; 712 sv_script_ctx_t sc = { 0, };
...@@ -679,12 +714,12 @@ main (int argc, char *argv[]) ...@@ -679,12 +714,12 @@ main (int argc, char *argv[])
679 size_t count = 0; 714 size_t count = 0;
680 int i = 0; 715 int i = 0;
681 716
682 int res; 717 int res = 0;
683 FILE *f = 0; 718 FILE *f = 0;
684 719
685 int opt; 720 int opt;
686 721
687 while ((opt = getopt (argc, argv, "hnvcdf:D:")) != -1) 722 while ((opt = getopt (argc, argv, "hnvcf:t:dD:")) != -1)
688 { 723 {
689 switch (opt) 724 switch (opt)
690 { 725 {
...@@ -703,6 +738,9 @@ main (int argc, char *argv[]) ...@@ -703,6 +738,9 @@ main (int argc, char *argv[])
703 case 'f': 738 case 'f':
704 ic.opt_mbox = optarg; 739 ic.opt_mbox = optarg;
705 break; 740 break;
741 case 't':
742 ic.opt_tickets = optarg;
743 break;
706 case 'd': 744 case 'd':
707 ic.opt_watch = 1; 745 ic.opt_watch = 1;
708 break; 746 break;
...@@ -728,6 +766,21 @@ main (int argc, char *argv[]) ...@@ -728,6 +766,21 @@ main (int argc, char *argv[])
728 case 2: ic.print_mask |= SV_PRN_ACT; break; 766 case 2: ic.print_mask |= SV_PRN_ACT; break;
729 default: ic.print_mask = ~0; break; 767 default: ic.print_mask = ~0; break;
730 } 768 }
769
770 if (ic.opt_tickets)
771 {
772 if ((res = wicket_create (&wicket, ic.opt_tickets)) != 0)
773 {
774 fprintf (stderr, "wicket create <%s> failed: %s\n",
775 ic.opt_tickets, strerror (res));
776 return 1;
777 }
778 if ((res = wicket_get_ticket (wicket, &ic.ticket, 0, 0)) != 0)
779 {
780 fprintf (stderr, "ticket get failed: %s\n", strerror (res));
781 return 1;
782 }
783 }
731 784
732 registrar_get_list (&bookie); 785 registrar_get_list (&bookie);
733 list_append (bookie, path_record); 786 list_append (bookie, path_record);
...@@ -742,6 +795,7 @@ main (int argc, char *argv[]) ...@@ -742,6 +795,7 @@ main (int argc, char *argv[])
742 ic.opt_mbox ? ic.opt_mbox : "default", strerror (res)); 795 ic.opt_mbox ? ic.opt_mbox : "default", strerror (res));
743 return 1; 796 return 1;
744 } 797 }
798
745 if (ic.print_mask & SV_PRN_MU) 799 if (ic.print_mask & SV_PRN_MU)
746 { 800 {
747 if ((res = mu_debug_create(&ic.debug, &ic))) 801 if ((res = mu_debug_create(&ic.debug, &ic)))
...@@ -761,6 +815,31 @@ main (int argc, char *argv[]) ...@@ -761,6 +815,31 @@ main (int argc, char *argv[])
761 } 815 }
762 mailbox_set_debug (mbox, ic.debug); 816 mailbox_set_debug (mbox, ic.debug);
763 } 817 }
818
819 if (ic.ticket)
820 {
821 folder_t folder = NULL;
822 authority_t auth = NULL;
823
824 if ((res = mailbox_get_folder (mbox, &folder)))
825 {
826 fprintf (stderr, "mailbox_get_folder failed: %s", strerror(res));
827 return 1;
828 }
829
830 if ((res = folder_get_authority (folder, &auth)))
831 {
832 fprintf (stderr, "folder_get_authority failed: %s", strerror(res));
833 return 1;
834 }
835
836 if ((res = authority_set_ticket (auth, ic.ticket)))
837 {
838 fprintf (stderr, "authority_set_ticket failed: %s", strerror(res));
839 return 1;
840 }
841 }
842
764 if (ic.opt_no_actions) 843 if (ic.opt_no_actions)
765 res = mailbox_open (mbox, MU_STREAM_READ); 844 res = mailbox_open (mbox, MU_STREAM_READ);
766 else 845 else
......