(mu-register-format): New primitive. Registers desired mailbox/mailer formats.
(mu_scm_init): Unconditionally register path_record format.
Showing
1 changed file
with
97 additions
and
7 deletions
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | 16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
17 | 17 | ||
18 | #include "mu_scm.h" | 18 | #include "mu_scm.h" |
19 | #include <mailutils/registrar.h> | ||
19 | 20 | ||
20 | #ifndef _PATH_SENDMAIL | 21 | #ifndef _PATH_SENDMAIL |
21 | # define _PATH_SENDMAIL "/usr/lib/sendmail" | 22 | # define _PATH_SENDMAIL "/usr/lib/sendmail" |
... | @@ -43,19 +44,104 @@ scm_makenum (unsigned long val) | ... | @@ -43,19 +44,104 @@ scm_makenum (unsigned long val) |
43 | void | 44 | void |
44 | mu_set_variable (const char *name, SCM value) | 45 | mu_set_variable (const char *name, SCM value) |
45 | { | 46 | { |
46 | #if GUILE_VERSION == 14 | ||
47 | scm_c_define (name, value); /*FIXME*/ | ||
48 | #else | ||
49 | scm_c_define (name, value); | 47 | scm_c_define (name, value); |
50 | #endif | ||
51 | } | 48 | } |
52 | 49 | ||
53 | |||
54 | SCM _mu_scm_package; /* STRING: PACKAGE */ | 50 | SCM _mu_scm_package; /* STRING: PACKAGE */ |
55 | SCM _mu_scm_version; /* STRING: VERSION */ | 51 | SCM _mu_scm_version; /* STRING: VERSION */ |
56 | SCM _mu_scm_mailer; /* STRING: Default mailer path. */ | 52 | SCM _mu_scm_mailer; /* STRING: Default mailer path. */ |
57 | SCM _mu_scm_debug; /* NUM: Default debug level. */ | 53 | SCM _mu_scm_debug; /* NUM: Default debug level. */ |
58 | 54 | ||
55 | struct format_record { | ||
56 | char *name; | ||
57 | record_t *record; | ||
58 | }; | ||
59 | |||
60 | static struct format_record format_table[] = { | ||
61 | { "mbox", &mbox_record }, | ||
62 | { "mh", &mh_record }, | ||
63 | { "pop", &pop_record }, | ||
64 | { "imap", &imap_record }, | ||
65 | { "sendmail", &sendmail_record }, | ||
66 | { "smtp", &smtp_record }, | ||
67 | { NULL, NULL }, | ||
68 | }; | ||
69 | |||
70 | static record_t * | ||
71 | find_format (const struct format_record *table, const char *name) | ||
72 | { | ||
73 | for (; table->name; table++) | ||
74 | if (strcmp (table->name, name) == 0) | ||
75 | break; | ||
76 | return table->record; | ||
77 | } | ||
78 | |||
79 | static int | ||
80 | register_format (const char *name) | ||
81 | { | ||
82 | int status = 0; | ||
83 | list_t reglist = NULL; | ||
84 | |||
85 | status = registrar_get_list (®list); | ||
86 | if (status) | ||
87 | return status; | ||
88 | |||
89 | if (!name) | ||
90 | { | ||
91 | struct format_record *table; | ||
92 | for (table = format_table; table->name; table++) | ||
93 | list_append (reglist, *table->record); | ||
94 | status = 0; | ||
95 | } | ||
96 | else | ||
97 | { | ||
98 | record_t *record = find_format (format_table, name); | ||
99 | if (record) | ||
100 | status = list_append (reglist, *record); | ||
101 | else | ||
102 | status = EINVAL; | ||
103 | } | ||
104 | return status; | ||
105 | } | ||
106 | |||
107 | |||
108 | SCM_DEFINE (mu_register_format, "mu-register-format", 0, 0, 1, | ||
109 | (SCM REST), | ||
110 | "Registers desired mailutils formats. Takes any number of arguments.\n" | ||
111 | "Allowed arguments are:\n" | ||
112 | " \"mbox\" Regular UNIX mbox format\n" | ||
113 | " \"mh\" MH mailbox format\n" | ||
114 | " \"pop\" POP mailbox format\n" | ||
115 | " \"imap\" IMAP mailbox format\n" | ||
116 | " \"sendmail\" sendmail mailer\n" | ||
117 | " \"smtp\" smtp mailer\n" | ||
118 | "\n" | ||
119 | "If called without arguments, registers all available formats\n") | ||
120 | #define FUNC_NAME s_mu_register_format | ||
121 | { | ||
122 | SCM status; | ||
123 | |||
124 | if (REST == SCM_EOL) | ||
125 | { | ||
126 | register_format (NULL); | ||
127 | status = SCM_BOOL_T; | ||
128 | } | ||
129 | else | ||
130 | { | ||
131 | status = SCM_BOOL_T; | ||
132 | for (; REST != SCM_EOL; REST = SCM_CDR (REST)) | ||
133 | { | ||
134 | SCM scm = SCM_CAR (REST); | ||
135 | SCM_ASSERT (SCM_NIMP (scm) && SCM_STRINGP (scm), | ||
136 | scm, SCM_ARGn, FUNC_NAME); | ||
137 | if (register_format (SCM_STRING_CHARS (scm))) | ||
138 | status = SCM_BOOL_F; | ||
139 | } | ||
140 | } | ||
141 | return status; | ||
142 | } | ||
143 | #undef FUNC_NAME | ||
144 | |||
59 | static struct | 145 | static struct |
60 | { | 146 | { |
61 | char *name; | 147 | char *name; |
... | @@ -71,7 +157,6 @@ static struct | ... | @@ -71,7 +157,6 @@ static struct |
71 | { "MU-ATTRIBUTE-RECENT", MU_ATTRIBUTE_RECENT }, | 157 | { "MU-ATTRIBUTE-RECENT", MU_ATTRIBUTE_RECENT }, |
72 | { NULL, 0 } | 158 | { NULL, 0 } |
73 | }; | 159 | }; |
74 | |||
75 | 160 | ||
76 | /* Initialize the library */ | 161 | /* Initialize the library */ |
77 | void | 162 | void |
... | @@ -79,7 +164,8 @@ mu_scm_init () | ... | @@ -79,7 +164,8 @@ mu_scm_init () |
79 | { | 164 | { |
80 | char *defmailer; | 165 | char *defmailer; |
81 | int i; | 166 | int i; |
82 | 167 | list_t lst; | |
168 | |||
83 | asprintf (&defmailer, "sendmail:%s", _PATH_SENDMAIL); | 169 | asprintf (&defmailer, "sendmail:%s", _PATH_SENDMAIL); |
84 | _mu_scm_mailer = scm_makfrom0str (defmailer); | 170 | _mu_scm_mailer = scm_makfrom0str (defmailer); |
85 | mu_set_variable ("mu-mailer", _mu_scm_mailer); | 171 | mu_set_variable ("mu-mailer", _mu_scm_mailer); |
... | @@ -105,4 +191,8 @@ mu_scm_init () | ... | @@ -105,4 +191,8 @@ mu_scm_init () |
105 | mu_scm_logger_init (); | 191 | mu_scm_logger_init (); |
106 | mu_scm_port_init (); | 192 | mu_scm_port_init (); |
107 | mu_scm_mime_init (); | 193 | mu_scm_mime_init (); |
194 | #include "mu_scm.x" | ||
195 | |||
196 | registrar_get_list (&lst); | ||
197 | list_append (lst, path_record); | ||
108 | } | 198 | } | ... | ... |
-
Please register or sign in to post a comment