~ubuntu-branches/ubuntu/trusty/postfix/trusty-proposed

« back to all changes in this revision

Viewing changes to src/oqmgr/qmgr_defer.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2005-02-27 09:33:07 UTC
  • Revision ID: james.westby@ubuntu.com-20050227093307-cn789t27ibnlh6tf
Tags: upstream-2.1.5
ImportĀ upstreamĀ versionĀ 2.1.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*++
 
2
/* NAME
 
3
/*      qmgr_defer
 
4
/* SUMMARY
 
5
/*      deal with mail that must be delivered later
 
6
/* SYNOPSIS
 
7
/*      #include "qmgr.h"
 
8
/*
 
9
/*      void    qmgr_defer_recipient(message, recipient, reason)
 
10
/*      QMGR_MESSAGE *message;
 
11
/*      QMGR_RCPT *recipient;
 
12
/*      const char *reason;
 
13
/*
 
14
/*      void    qmgr_defer_todo(queue, reason)
 
15
/*      QMGR_QUEUE *queue;
 
16
/*      const char *reason;
 
17
/*
 
18
/*      QMGR_QUEUE *qmgr_defer_transport(transport, reason)
 
19
/*      QMGR_TRANSPORT *transport;
 
20
/*      const char *reason;
 
21
/* DESCRIPTION
 
22
/*      qmgr_defer_recipient() defers delivery of the named message to
 
23
/*      the named recipient. It updates the message structure and writes
 
24
/*      a log entry.
 
25
/*
 
26
/*      qmgr_defer_todo() iterates over all "todo" deliveries queued for
 
27
/*      the named site, and calls qmgr_defer_recipient() for each recipient
 
28
/*      found.  Side effects caused by qmgr_entry_done(), qmgr_queue_done(),
 
29
/*      and by qmgr_active_done(): in-core queue entries will disappear,
 
30
/*      in-core queues may disappear, in-core and on-disk messages may
 
31
/*      disappear, bounces may be sent, new in-core queues, queue entries
 
32
/*      and recipients may appear.
 
33
/*
 
34
/*      qmgr_defer_transport() calls qmgr_defer_todo() for each queue
 
35
/*      that depends on the named transport. See there for side effects.
 
36
/*
 
37
/*      Arguments:
 
38
/* .IP recipient
 
39
/*      A recipient address; used for logging purposes, and for updating
 
40
/*      the message-specific \fIdefer\fR log.
 
41
/* .IP queue
 
42
/*      Specifies a queue with delivery requests for a specific next-hop
 
43
/*      host (or local user).
 
44
/* .IP transport
 
45
/*      Specifies a message delivery transport.
 
46
/* .IP reason
 
47
/*      Free-format text that describes why delivery is deferred; this
 
48
/*      used for logging purposes, and for updating the message-specific
 
49
/*      \fIdefer\fR log.
 
50
/* BUGS
 
51
/*      The side effects of calling this routine are quite dramatic.
 
52
/* DIAGNOSTICS
 
53
/*      Panic: consistency check failure. Fatal: out of memory.
 
54
/* LICENSE
 
55
/* .ad
 
56
/* .fi
 
57
/*      The Secure Mailer license must be distributed with this software.
 
58
/* AUTHOR(S)
 
59
/*      Wietse Venema
 
60
/*      IBM T.J. Watson Research
 
61
/*      P.O. Box 704
 
62
/*      Yorktown Heights, NY 10598, USA
 
63
/*--*/
 
64
 
 
65
/* System library. */
 
66
 
 
67
#include <sys_defs.h>
 
68
 
 
69
/* Utility library. */
 
70
 
 
71
#include <msg.h>
 
72
#include <vstream.h>
 
73
 
 
74
/* Global library. */
 
75
 
 
76
#include <defer.h>
 
77
 
 
78
/* Application-specific. */
 
79
 
 
80
#include "qmgr.h"
 
81
 
 
82
/* qmgr_defer_transport - defer todo entries for named transport */
 
83
 
 
84
void    qmgr_defer_transport(QMGR_TRANSPORT *transport, const char *reason)
 
85
{
 
86
    char   *myname = "qmgr_defer_transport";
 
87
    QMGR_QUEUE *queue;
 
88
    QMGR_QUEUE *next;
 
89
 
 
90
    /*
 
91
     * Sanity checks.
 
92
     */
 
93
    if (reason == 0)
 
94
        msg_panic("%s: null reason", myname);
 
95
    if (msg_verbose)
 
96
        msg_info("defer transport %s: %s", transport->name, reason);
 
97
 
 
98
    /*
 
99
     * Proceed carefully. Queues may disappear as a side effect.
 
100
     */
 
101
    for (queue = transport->queue_list.next; queue; queue = next) {
 
102
        next = queue->peers.next;
 
103
        qmgr_defer_todo(queue, reason);
 
104
    }
 
105
}
 
106
 
 
107
/* qmgr_defer_todo - defer all todo queue entries for specific site */
 
108
 
 
109
void    qmgr_defer_todo(QMGR_QUEUE *queue, const char *reason)
 
110
{
 
111
    char   *myname = "qmgr_defer_todo";
 
112
    QMGR_ENTRY *entry;
 
113
    QMGR_ENTRY *next;
 
114
    QMGR_MESSAGE *message;
 
115
    QMGR_RCPT *recipient;
 
116
    int     nrcpt;
 
117
 
 
118
    /*
 
119
     * Sanity checks.
 
120
     */
 
121
    if (reason == 0)
 
122
        msg_panic("%s: null reason", myname);
 
123
    if (msg_verbose)
 
124
        msg_info("defer site %s: %s", queue->name, reason);
 
125
 
 
126
    /*
 
127
     * Proceed carefully. Queue entries will disappear as a side effect.
 
128
     */
 
129
    for (entry = queue->todo.next; entry != 0; entry = next) {
 
130
        next = entry->peers.next;
 
131
        message = entry->message;
 
132
        for (nrcpt = 0; nrcpt < entry->rcpt_list.len; nrcpt++) {
 
133
            recipient = entry->rcpt_list.info + nrcpt;
 
134
            qmgr_defer_recipient(message, recipient, reason);
 
135
        }
 
136
        qmgr_entry_done(entry, QMGR_QUEUE_TODO);
 
137
    }
 
138
}
 
139
 
 
140
/* qmgr_defer_recipient - defer delivery of specific recipient */
 
141
 
 
142
void    qmgr_defer_recipient(QMGR_MESSAGE *message, QMGR_RCPT *recipient,
 
143
                                     const char *reason)
 
144
{
 
145
    char   *myname = "qmgr_defer_recipient";
 
146
 
 
147
    /*
 
148
     * Sanity checks.
 
149
     */
 
150
    if (reason == 0)
 
151
        msg_panic("%s: reason 0", myname);
 
152
 
 
153
    /*
 
154
     * Update the message structure and log the message disposition.
 
155
     */
 
156
    message->flags |= defer_append(message->tflags, message->queue_id,
 
157
                                   recipient->orig_rcpt, recipient->address,
 
158
                                   recipient->offset, "none",
 
159
                                   message->arrival_time,
 
160
       "delivery temporarily suspended: %s", reason);
 
161
}