Commit 3dc97482 3dc974822b70bec356ef67234667a85033260e1b by Sergey Poznyakoff

Added to repository

1 parent d81db5ae
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <mu_scm.h>
19
20 static void _scheme_main (void *closure, int argc, char **argv);
21
22 void
23 mu_process_mailbox (int argc, char *argv[], guimb_param_t *param)
24 {
25 scm_boot_guile (argc, argv, _scheme_main, param);
26 }
27
28 SCM _current_mailbox;
29 SCM _user_name;
30
31 static SCM
32 catch_body (void *closure)
33 {
34 guimb_param_t *param = closure;
35 return param->catch_body (param->data, param->mbox);
36 }
37
38 void
39 _scheme_main (void *closure, int argc, char **argv)
40 {
41 guimb_param_t *param = closure;
42 SCM *scm_loc;
43
44 if (param->debug_guile)
45 {
46 SCM_DEVAL_P = 1;
47 SCM_BACKTRACE_P = 1;
48 SCM_RECORD_POSITIONS_P = 1;
49 SCM_RESET_DEBUG_MODE;
50 }
51
52 /* Initialize scheme library */
53 mu_scm_init ();
54
55 /* Provide basic primitives */
56 #include <mu_guimb.x>
57
58 _current_mailbox = mu_scm_mailbox_create (param->mbox);
59 scm_loc = SCM_CDRLOC (scm_sysintern ("current-mailbox", SCM_EOL));
60 *scm_loc = _current_mailbox;
61
62 _user_name = param->user_name ?
63 scm_makfrom0str (param->user_name) : SCM_BOOL_F;
64 scm_loc = SCM_CDRLOC (scm_sysintern ("user-name", SCM_EOL));
65 *scm_loc = _user_name;
66
67 if (param->init)
68 param->init (param->data);
69
70 do {
71 scm_internal_lazy_catch (SCM_BOOL_T,
72 catch_body, closure,
73 param->catch_handler, param->data);
74 } while (param->next && param->next (param->data, param->mbox));
75
76 if (param->exit)
77 exit (param->exit (param->data, param->mbox));
78
79 exit (0);
80 }
1 AUTOMAKE_OPTIONS = ../lib/ansi2knr
2 INCLUDES =-I$(srcdir) -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir)/libmu_scm
3
4 libexec_PROGRAMS = mail.local
5 mail_local_SOURCES = main.c mailquota.c script.c mail.local.h
6
7 mail_local_LDADD = @LIBMU_SCM@ ../mailbox/libmailbox.la ../lib/libmailutils.a @GUILE_LIBS@
8
9 install-exec-hook:
10 for i in $(libexec_PROGRAMS); do\
11 chown root:mail $(libexecdir)/$$i;\
12 chmod 4755 $(libexecdir)/$$i;\
13 done
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #if defined(HAVE_CONFIG_H)
19 # include <config.h>
20 #endif
21 #include <errno.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <string.h>
26 #include <syslog.h>
27 #include <pwd.h>
28 #include <grp.h>
29 #include <stdarg.h>
30 #include <sys/stat.h>
31 #include <sysexits.h>
32 #include "getopt.h"
33
34 #ifdef HAVE_STRINGS_H
35 # include <strings.h>
36 #endif
37
38 #include <mailutils/mailbox.h>
39 #include <mailutils/message.h>
40 #include <mailutils/error.h>
41 #include <mailutils/registrar.h>
42 #include <mailutils/stream.h>
43 #include <mailutils/mutil.h>
44 #include <mu_dbm.h>
45
46 /* Debug */
47 extern int debug_level;
48 #define dbg() if (debug_level) debug
49
50 /* mailquota settings */
51 #define MQUOTA_OK 0
52 #define MQUOTA_EXCEEDED 1
53 #define MQUOTA_UNLIMITED 2
54
55 struct mda_data
56 {
57 FILE *fp;
58 char *progfile;
59 char *progfile_pattern;
60 char **argv;
61 char *tempfile;
62 };
63
64 extern char *quotadbname;
65 extern int exit_code;
66
67 extern void setgroupquota (char *str);
68 extern int check_quota (char *name, size_t size, size_t *rest);
69
70 int mda (FILE *fp, char *username, mailbox_t mbox);
71 char *make_progfile_name (char *pattern, char *username);
72
73 #ifdef WITH_GUILE
74 int prog_mda (struct mda_data *data);
75 #endif
76
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <mail.local.h>
19
20 #ifdef USE_DBM
21
22 #define DEFRETVAL MQUOTA_UNLIMITED
23
24 size_t groupquota = 5*1024*1024UL;
25 static int get_size (char *, size_t *, char **);
26
27 int
28 get_size (char *str, size_t *size, char **endp)
29 {
30 size_t s;
31
32 s = strtol (str, &str, 0);
33 switch (*str)
34 {
35 case 0:
36 break;
37 case 'k':
38 case 'K':
39 s *= 1024;
40 break;
41 case 'm':
42 case 'M':
43 s *= 1024*1024;
44 break;
45 default:
46 *endp = str;
47 return -1;
48 }
49 *size = s;
50 return 0;
51 }
52
53 int
54 check_quota (char *name, size_t size, size_t *rest)
55 {
56 DBM_FILE db;
57 DBM_DATUM named, contentd;
58 size_t quota;
59 char buffer[64];
60 int unlimited = 0;
61 int rc;
62
63 if (!quotadbname || mu_dbm_open (quotadbname, &db, MU_STREAM_READ, 0600))
64 return DEFRETVAL;
65
66 memset (&named, 0, sizeof named);
67 MU_DATUM_PTR (named) = name;
68 MU_DATUM_SIZE (named) = strlen (name);
69 rc = mu_dbm_fetch (db, named, &contentd);
70 if (rc || !MU_DATUM_PTR (contentd))
71 {
72 /* User not in database, try default quota */
73 memset (&named, 0, sizeof named);
74 MU_DATUM_PTR (named) = "DEFAULT";
75 MU_DATUM_SIZE (named) = strlen ("DEFAULT");
76 rc = mu_dbm_fetch (db, named, &contentd);
77 if (rc)
78 {
79 //mu_error("can't fetch data: %s", strerror (rc));
80 return DEFRETVAL;
81 }
82 if (!MU_DATUM_PTR (contentd))
83 return DEFRETVAL;
84 }
85
86 if (strncasecmp("none",
87 MU_DATUM_PTR (contentd),
88 MU_DATUM_SIZE (contentd)) == 0)
89 unlimited = 1;
90 else if (MU_DATUM_SIZE (contentd) > sizeof(buffer)-1)
91 {
92 mu_error ("mailbox quota for `%s' is too big: %d digits",
93 name, MU_DATUM_SIZE (contentd));
94 quota = groupquota;
95 }
96 else
97 {
98 char *p;
99
100 strncpy(buffer, MU_DATUM_PTR (contentd), MU_DATUM_SIZE (contentd));
101 buffer[MU_DATUM_SIZE (contentd)] = 0;
102 quota = strtoul (buffer, &p, 0);
103 if (get_size (buffer, &quota, &p))
104 {
105 mu_error ("bogus mailbox quota for `%s' (near `%s')", name, p);
106 quota = groupquota;
107 }
108 }
109
110 mu_dbm_close (db);
111 if (unlimited)
112 return MQUOTA_UNLIMITED;
113 else if (quota < size) /* Mailbox full */
114 return MQUOTA_EXCEEDED;
115
116 if (rest)
117 *rest = quota - size;
118
119 return MQUOTA_OK;
120 }
121
122 #endif
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <mail.local.h>
19
20 #ifdef WITH_GUILE
21 #include <mu_scm.h>
22
23 SCM mda_catch_body (void *data, mailbox_t mbox);
24 SCM mda_catch_handler (void *unused, SCM tag, SCM throw_args);
25 int mda_next (void *data, mailbox_t mbox);
26 int mda_exit (void *data, mailbox_t mbox);
27 int mda_init (void *data);
28
29 int
30 prog_mda (struct mda_data *data)
31 {
32 char *x_argv[2];
33 guimb_param_t param;
34 mailbox_t mbox;
35
36 x_argv[0] = "mail.local";
37 x_argv[1] = NULL;
38
39 fflush (data->fp);
40 if (mailbox_create (&mbox, data->tempfile)
41 || mailbox_open (mbox, MU_STREAM_RDWR) != 0)
42 {
43 mailer_err ("can't open temporary storage");
44 return EX_UNAVAILABLE;
45 }
46
47 unlink (data->tempfile);
48
49 param.debug_guile = 1 /*FIXME*/;
50 param.mbox = mbox;
51 param.user_name = NULL;
52 param.init = mda_init;
53 param.catch_body = mda_catch_body;
54 param.catch_handler = mda_catch_handler;
55 param.next = mda_next;
56 param.exit = mda_exit;
57 param.data = data;
58
59 mu_process_mailbox (1, x_argv, &param);
60 return EX_UNAVAILABLE;
61 }
62
63 int
64 mda_init (void *data)
65 {
66 struct mda_data *md = data;
67 md->progfile = make_progfile_name (md->progfile_pattern, md->argv[0]);
68 return 0;
69 }
70
71 SCM
72 mda_catch_body (void *data, mailbox_t mbox)
73 {
74 struct mda_data *md = data;
75
76 if (access (md->progfile, R_OK))
77 {
78 syslog (LOG_ERR, "access to %s failed: %m", md->progfile);
79 }
80 else
81 scm_primitive_load (scm_makfrom0str (md->progfile));
82 mda (md->fp, md->argv[0], mbox);
83 return SCM_BOOL_F;
84 }
85
86 SCM
87 mda_catch_handler (void *data, SCM tag, SCM throw_args)
88 {
89 exit_code = EX_TEMPFAIL;
90 return scm_handle_by_message_noexit ("mail.local", tag, throw_args);
91 }
92
93 int
94 mda_next (void *data, mailbox_t mbox)
95 {
96 struct mda_data *md = data;
97 message_t mesg = NULL;
98 attribute_t attr = NULL;
99
100 md->argv++;
101 if (*md->argv == NULL)
102 return 0;
103 if (md->progfile)
104 free (md->progfile);
105 md->progfile = make_progfile_name (md->progfile_pattern, *md->argv);
106
107 mailbox_get_message (mbox, 1, &mesg);
108 message_get_attribute (mesg, &attr);
109 attribute_unset_deleted (attr);
110
111 return md->progfile != NULL;
112 }
113
114 int
115 mda_exit (void *data, mailbox_t mbox)
116 {
117 return exit_code;
118 }
119
120 #endif