aboutsummaryrefslogtreecommitdiffstats
path: root/spool2dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'spool2dir.c')
-rw-r--r--spool2dir.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/spool2dir.c b/spool2dir.c
index aa53e71..edd5bd3 100644
--- a/spool2dir.c
+++ b/spool2dir.c
@@ -112,30 +112,30 @@ struct antispam_transaction_context {
};
-void backend_rollback(struct antispam_transaction_context *ast)
+static void backend_rollback(struct antispam_transaction_context *ast)
{
i_free(ast);
}
-int backend_commit(struct mailbox_transaction_context *ctx __attr_unused__,
- struct antispam_transaction_context *ast)
+static int backend_commit(struct mailbox_transaction_context *ctx __attr_unused__,
+ struct antispam_transaction_context *ast)
{
i_free(ast);
return 0;
}
-int backend_handle_mail(struct mailbox_transaction_context *t,
- struct antispam_transaction_context *ast,
- struct mail *mail, enum classification wanted)
+static int backend_handle_mail(struct mailbox_transaction_context *t,
+ struct antispam_transaction_context *ast,
+ struct mail *mail, enum classification wanted)
{
struct istream *mailstream;
struct ostream *outstream;
- int ret;
+ int ret = -1;
const char *dest, *buf;
const unsigned char *beginning;
size_t size;
- int fd;
+ int fd = -1;
i_assert(ast);
@@ -171,13 +171,14 @@ int backend_handle_mail(struct mailbox_transaction_context *t,
while (ast->count <= 9999) {
buf = t_strdup_printf(dest, (long)time(0), (long)++ast->count);
fd = open(buf, O_CREAT | O_EXCL | O_WRONLY, 0600);
- if(fd >= 0 || errno != EEXIST)
+ if (fd >= 0 || errno != EEXIST)
break;
/* current filename in buf already exists, zap it */
t_pop();
t_push();
- /* buf is invalid now ! */
+ /* buf is invalid now! */
}
+
if (fd < 0) {
debug("spool2dir backend: Failed to create spool file %s: %s\n",
dest, strerror(errno));
@@ -188,6 +189,7 @@ int backend_handle_mail(struct mailbox_transaction_context *t,
}
/* buf still points to allocated memory, because fd >= 0 */
+
outstream = o_stream_create_from_fd(fd, t->box->pool);
if (!outstream) {
mail_storage_set_error(t->box->storage,
@@ -198,7 +200,6 @@ int backend_handle_mail(struct mailbox_transaction_context *t,
if (i_stream_read_data(mailstream, &beginning, &size, 5) < 0 ||
size < 5) {
- ret = -1;
mail_storage_set_error(t->box->storage,
ME(NOTPOSSIBLE)
"Failed to read mail beginning");
@@ -210,7 +211,6 @@ int backend_handle_mail(struct mailbox_transaction_context *t,
i_stream_read_next_line(mailstream);
if (o_stream_send_istream(outstream, mailstream) < 0) {
- ret = -1;
mail_storage_set_error(t->box->storage,
ME(NOTPOSSIBLE)
"Failed to copy to spool file");
@@ -223,26 +223,27 @@ int backend_handle_mail(struct mailbox_transaction_context *t,
o_stream_destroy(&outstream);
out_close:
close(fd);
- out:
if (ret)
unlink(buf);
-
+ out:
t_pop();
return ret;
}
-void backend_init(pool_t pool __attr_unused__)
+static void backend_init(pool_t pool __attr_unused__)
{
- if((spamspool = get_setting("SPOOL2DIR_SPAM")))
+ spamspool = get_setting("SPOOL2DIR_SPAM");
+ if (spamspool)
debug("spool2dir spamspool %s\n", spamspool);
- if((hamspool = get_setting("SPOOL2DIR_NOTSPAM")))
+ hamspool = get_setting("SPOOL2DIR_NOTSPAM");
+ if (hamspool)
debug("spool2dir hamspool %s\n", hamspool);
}
-struct antispam_transaction_context *
- backend_start(struct mailbox *box __attr_unused__)
+static struct antispam_transaction_context *
+backend_start(struct mailbox *box __attr_unused__)
{
struct antispam_transaction_context *ast;
@@ -254,6 +255,15 @@ struct antispam_transaction_context *
}
-void backend_exit(void)
+static void backend_exit(void)
{
}
+
+struct backend spool2dir_backend = {
+ .init = backend_init,
+ .exit = backend_exit,
+ .handle_mail = backend_handle_mail,
+ .start = backend_start,
+ .rollback = backend_rollback,
+ .commit = backend_commit,
+};