~ubuntu-branches/ubuntu/hoary/postfix/hoary-security

« back to all changes in this revision

Viewing changes to src/global/sent.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-10-06 11:50:33 UTC
  • Revision ID: james.westby@ubuntu.com-20041006115033-ooo6yfg6kmoteu04
Tags: upstream-2.1.3
ImportĀ upstreamĀ versionĀ 2.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*++
 
2
/* NAME
 
3
/*      sent 3
 
4
/* SUMMARY
 
5
/*      log that a message was sent
 
6
/* SYNOPSIS
 
7
/*      #include <sent.h>
 
8
/*
 
9
/*      int     sent(flags, queue_id, orig_rcpt, recipient, offset, relay,
 
10
/*                      entry, format, ...)
 
11
/*      int     flags;
 
12
/*      const char *queue_id;
 
13
/*      const char *orig_rcpt;
 
14
/*      const char *recipient;
 
15
/*      long    offset;
 
16
/*      const char *relay;
 
17
/*      time_t  entry;
 
18
/*      const char *format;
 
19
/*
 
20
/*      int     vsent(flags, queue_id, orig_rcpt, recipient, offset, relay,
 
21
/*                      entry, format, ap)
 
22
/*      int     flags;
 
23
/*      const char *queue_id;
 
24
/*      const char *orig_rcpt;
 
25
/*      const char *recipient;
 
26
/*      long    offset;
 
27
/*      const char *relay;
 
28
/*      time_t  entry;
 
29
/*      const char *format;
 
30
/*      va_list ap;
 
31
/* DESCRIPTION
 
32
/*      sent() logs that a message was successfully delivered,
 
33
/*      updates the address verification service, or updates a
 
34
/*      message delivery record on request by the sender. The
 
35
/*      flags argument determines the action.
 
36
/*
 
37
/*      vsent() implements an alternative interface.
 
38
/*
 
39
/*      Arguments:
 
40
/* .IP flags
 
41
/*      Zero or more of the following:
 
42
/* .RS
 
43
/* .IP SENT_FLAG_NONE
 
44
/*      The message is a normal delivery request.
 
45
/* .IP DEL_REQ_FLAG_VERIFY
 
46
/*      The message is an address verification probe. Update the
 
47
/*      address verification database.
 
48
/* .IP DEL_REQ_FLAG_EXPAND
 
49
/*      The message is an address expansion probe. Update the
 
50
/*      message delivery record.
 
51
/* .IP DEL_REQ_FLAG_RECORD
 
52
/*      This is a normal message with logged delivery. Update the
 
53
/*      the message delivery record.
 
54
/* .RE
 
55
/* .IP queue_id
 
56
/*      The message queue id.
 
57
/* .IP orig_rcpt
 
58
/*      The original envelope recipient address. If unavailable,
 
59
/*      specify a null string or a null pointer.
 
60
/* .IP recipient
 
61
/*      The recipient address.
 
62
/* .IP offset
 
63
/*      Queue file offset of the recipient record.
 
64
/* .IP relay
 
65
/*      Name of the host we're talking to.
 
66
/* .IP entry
 
67
/*      Message arrival time.
 
68
/* .IP format
 
69
/*      Optional additional information.
 
70
/* DIAGNOSTICS
 
71
/*      A non-zero result means the operation failed.
 
72
/*
 
73
/*      Fatal: out of memory.
 
74
/* BUGS
 
75
/*      Should be replaced by routines with an attribute-value based
 
76
/*      interface instead of an interface that uses a rigid argument list.
 
77
/* LICENSE
 
78
/* .ad
 
79
/* .fi
 
80
/*      The Secure Mailer license must be distributed with this software.
 
81
/* AUTHOR(S)
 
82
/*      Wietse Venema
 
83
/*      IBM T.J. Watson Research
 
84
/*      P.O. Box 704
 
85
/*      Yorktown Heights, NY 10598, USA
 
86
/*--*/
 
87
 
 
88
/* System library. */
 
89
 
 
90
#include <sys_defs.h>
 
91
#include <stdio.h>
 
92
#include <stdlib.h>                     /* 44BSD stdarg.h uses abort() */
 
93
#include <stdarg.h>
 
94
#include <string.h>
 
95
 
 
96
#ifdef STRCASECMP_IN_STRINGS_H
 
97
#include <strings.h>
 
98
#endif
 
99
 
 
100
/* Utility library. */
 
101
 
 
102
#include <msg.h>
 
103
#include <vstring.h>
 
104
 
 
105
/* Global library. */
 
106
 
 
107
#include <mail_params.h>
 
108
#include <verify.h>
 
109
#include <log_adhoc.h>
 
110
#include <trace.h>
 
111
#include <defer.h>
 
112
#include <sent.h>
 
113
 
 
114
/* Application-specific. */
 
115
 
 
116
/* sent - log that a message was sent */
 
117
 
 
118
int     sent(int flags, const char *id, const char *orig_rcpt,
 
119
                     const char *recipient, long offset, const char *relay,
 
120
                     time_t entry, const char *fmt,...)
 
121
{
 
122
    va_list ap;
 
123
    int     status;
 
124
 
 
125
    va_start(ap, fmt);
 
126
    status = vsent(flags, id, orig_rcpt, recipient,
 
127
                   offset, relay, entry, fmt, ap);
 
128
    va_end(ap);
 
129
    return (status);
 
130
}
 
131
 
 
132
/* vsent - log that a message was sent */
 
133
 
 
134
int     vsent(int flags, const char *id, const char *orig_rcpt,
 
135
                      const char *recipient, long offset, const char *relay,
 
136
                      time_t entry, const char *fmt, va_list ap)
 
137
{
 
138
    int     status;
 
139
 
 
140
    /*
 
141
     * MTA-requested address verification information is stored in the verify
 
142
     * service database.
 
143
     */
 
144
    if (flags & DEL_REQ_FLAG_VERIFY) {
 
145
        status = vverify_append(id, orig_rcpt, recipient, relay, entry,
 
146
                                "deliverable", DEL_RCPT_STAT_OK, fmt, ap);
 
147
        return (status);
 
148
    }
 
149
 
 
150
    /*
 
151
     * User-requested address verification information is logged and mailed
 
152
     * to the requesting user.
 
153
     */
 
154
    if (flags & DEL_REQ_FLAG_EXPAND) {
 
155
        status = vtrace_append(flags, id, orig_rcpt, recipient, relay,
 
156
                               entry, "2.0.0", "deliverable", fmt, ap);
 
157
        return (status);
 
158
    }
 
159
 
 
160
    /*
 
161
     * Normal mail delivery. May also send a delivery record to the user.
 
162
     */
 
163
    else {
 
164
        VSTRING *text = vstring_alloc(10);
 
165
 
 
166
        vstring_vsprintf(text, fmt, ap);
 
167
        if ((flags & DEL_REQ_FLAG_RECORD) == 0
 
168
            || trace_append(flags, id, orig_rcpt, recipient, relay,
 
169
                            entry, "2.0.0", "delivered",
 
170
                            "%s", vstring_str(text)) == 0) {
 
171
            log_adhoc(id, orig_rcpt, recipient, relay,
 
172
                      entry, "sent", "%s", vstring_str(text));
 
173
            status = 0;
 
174
        } else {
 
175
            status = defer_append(flags, id, orig_rcpt, recipient, offset,
 
176
                                  relay, entry, "%s: %s service failed",
 
177
                                  id, var_trace_service);
 
178
        }
 
179
        vstring_free(text);
 
180
        return (status);
 
181
    }
 
182
}