deliver.c revision 2b312f0183750c8cb9049510df4b6cd2027f9f43
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* Copyright (C) 2005-2006 Timo Sirainen */
395682d473b161c86165e7b9323ce4e45afb94bdTimo Sirainen#define DEFAULT_CONFIG_FILE SYSCONFDIR"/dovecot.conf"
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen#define DEFAULT_AUTH_SOCKET_PATH PKG_RUNDIR"/auth-master"
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen#define DEFAULT_SENDMAIL_PATH "/usr/lib/sendmail"
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen/* After buffer grows larger than this, create a temporary file to /tmp
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen where to read the mail. */
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainenvoid (*hook_mail_storage_created)(struct mail_storage *storage) = NULL;
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainenstatic void sig_die(int signo, void *context __attr_unused__)
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen /* warn about being killed because of some signal, except SIGINT (^C)
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen which is too common at least while testing :) */
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainenstatic struct mailbox *
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainenmailbox_open_or_create_synced(struct mail_storage *storage, const char *name)
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen box = mailbox_open(storage, name, NULL, MAILBOX_OPEN_FAST |
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen (void)mail_storage_get_last_error(storage, &syntax, &temp);
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen /* probably the mailbox just doesn't exist. try creating it. */
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen if (mail_storage_mailbox_create(storage, name, FALSE) < 0)
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen /* and try opening again */
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen box = mailbox_open(storage, name, NULL, MAILBOX_OPEN_FAST |
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainenint deliver_save(struct mail_storage *storage, const char *mailbox,
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen const char *const *keywords)
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen box = mailbox_open_or_create_synced(storage, mailbox);
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen t = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_EXTERNAL);
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen if (mailbox_copy(t, mail, flags, kw, NULL) < 0)
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainenconst char *deliver_get_return_address(struct mail *mail)
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen const char *str;
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen str = mail_get_first_header(mail, "Return-Path");
(const unsigned char *)str,
const char *deliver_get_new_message_id(void)
static int count = 0;
if (fd < 0)
t_push();
line++;
quote = *p;
len--;
sections++;
sections--;
value++;
t_pop();
static const struct var_expand_table *
return tab;
if (p != NULL) {
while (env != p) {
env++;
const char *mbox_hdr;
"/tmp/dovecot.deliver.");
return input;
const char *prefix;
static void print_help(void)
struct mailbox_transaction_context *t;
int i, ret;
lib_init();
#ifdef SIGXFSZ
env_clean();
if (i == argc) {
if (i == argc) {
if (i == argc) {
print_help();
else if (process_euid != 0) {
if (ret != 0)
return ret;
/* MAIL comes from userdb, DEFAULT_MAIL_ENV from dovecot.conf */
TRUE);
if (ret <= 0) {
const char *error;
int ret;
if (temporary_error)
return EX_TEMPFAIL;
if (ret != 0)
lib_deinit();
return EX_OK;