~ubuntu-branches/ubuntu/trusty/postfix/trusty-updates

« back to all changes in this revision

Viewing changes to src/showq/showq.c

Tags: upstream-2.3.1
ImportĀ upstreamĀ versionĀ 2.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
#define SENDER_FORMAT   "%-11s%8ld %20.20s %s\n"
144
144
#define DROP_FORMAT     "%-10s%c%8ld %20.20s (maildrop queue, sender UID %u)\n"
145
145
 
146
 
static void showq_reasons(VSTREAM *, BOUNCE_LOG *, HTABLE *);
 
146
static void showq_reasons(VSTREAM *, BOUNCE_LOG *, RCPT_BUF *, DSN_BUF *, 
 
147
HTABLE *);
147
148
 
148
149
#define STR(x)  vstring_str(x)
149
150
 
160
161
    long    msg_size = 0;
161
162
    BOUNCE_LOG *logfile;
162
163
    HTABLE *dup_filter = 0;
 
164
    RCPT_BUF *rcpt_buf = 0;
 
165
    DSN_BUF *dsn_buf = 0;
163
166
    char    status = (strcmp(queue, MAIL_QUEUE_ACTIVE) == 0 ? '*' :
164
167
                      strcmp(queue, MAIL_QUEUE_HOLD) == 0 ? '!' : ' ');
165
168
    int     msg_size_ok = 0;
236
239
            && dup_filter == 0
237
240
            && (logfile = bounce_log_open(MAIL_QUEUE_DEFER, id, O_RDONLY, 0)) != 0) {
238
241
            dup_filter = htable_create(var_dup_filter_limit);
239
 
            showq_reasons(client, logfile, dup_filter);
 
242
            if (rcpt_buf == 0)
 
243
                rcpt_buf = rcpb_create();
 
244
            if (dsn_buf == 0)
 
245
                dsn_buf = dsb_create();
 
246
            showq_reasons(client, logfile, rcpt_buf, dsn_buf, dup_filter);
240
247
            if (bounce_log_close(logfile))
241
248
                msg_warn("close %s %s: %m", MAIL_QUEUE_DEFER, id);
242
249
        }
243
250
    }
244
251
    vstring_free(buf);
245
252
    vstring_free(printable_quoted_addr);
 
253
    if (rcpt_buf)
 
254
        rcpb_free(rcpt_buf);
 
255
    if (dsn_buf)
 
256
        dsb_free(dsn_buf);
246
257
    if (dup_filter)
247
258
        htable_free(dup_filter, (void (*) (char *)) 0);
248
259
}
249
260
 
250
261
/* showq_reasons - show deferral reasons */
251
262
 
252
 
static void showq_reasons(VSTREAM *client, BOUNCE_LOG *bp, HTABLE *dup_filter)
 
263
static void showq_reasons(VSTREAM *client, BOUNCE_LOG *bp, RCPT_BUF *rcpt_buf, 
 
264
DSN_BUF *dsn_buf, HTABLE *dup_filter)
253
265
{
254
266
    char   *saved_reason = 0;
255
267
    int     padding;
 
268
    RECIPIENT *rcpt = &rcpt_buf->rcpt;
 
269
    DSN    *dsn = &dsn_buf->dsn;
256
270
 
257
 
    while (bounce_log_read(bp) != 0) {
 
271
    while (bounce_log_read(bp, rcpt_buf, dsn_buf) != 0) {
258
272
 
259
273
        /*
260
274
         * Update the duplicate filter.
261
275
         */
262
276
        if (var_dup_filter_limit == 0
263
277
            || dup_filter->used < var_dup_filter_limit)
264
 
            if (htable_locate(dup_filter, bp->recipient) == 0)
265
 
                htable_enter(dup_filter, bp->recipient, (char *) 0);
 
278
            if (htable_locate(dup_filter, rcpt->address) == 0)
 
279
                htable_enter(dup_filter, rcpt->address, (char *) 0);
266
280
 
267
281
        /*
268
282
         * Don't print the reason when the previous recipient had the same
269
283
         * problem.
270
284
         */
271
 
        if (saved_reason == 0 || strcmp(saved_reason, bp->text) != 0) {
 
285
        if (saved_reason == 0 || strcmp(saved_reason, dsn->reason) != 0) {
272
286
            if (saved_reason)
273
287
                myfree(saved_reason);
274
 
            saved_reason = mystrdup(bp->text);
 
288
            saved_reason = mystrdup(dsn->reason);
275
289
            if ((padding = 76 - strlen(saved_reason)) < 0)
276
290
                padding = 0;
277
291
            vstream_fprintf(client, "%*s(%s)\n", padding, "", saved_reason);
278
292
        }
279
 
        vstream_fprintf(client, STRING_FORMAT, "", "", "", bp->recipient);
 
293
        vstream_fprintf(client, STRING_FORMAT, "", "", "", rcpt->address);
280
294
    }
281
295
    if (saved_reason)
282
296
        myfree(saved_reason);