1 /* $Id$ */
2
3 /*
4 * Copyright (c) 2006 Nicholas Marriott <nicholas.marriott@gmail.com>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <sys/types.h>
20
21 #include <stdio.h>
22 #include <string.h>
23
24 #include "fdm.h"
25 #include "deliver.h"
26
27 int deliver_stdout_deliver(struct deliver_ctx *, struct actitem *);
28 void deliver_stdout_desc(struct actitem *, char *, size_t);
29
30 struct deliver deliver_stdout = {
31 "stdout",
32 DELIVER_INCHILD,
33 deliver_stdout_deliver,
34 deliver_stdout_desc
35 };
36
37 int
deliver_stdout_deliver(struct deliver_ctx * dctx,unused struct actitem * ti)38 deliver_stdout_deliver(struct deliver_ctx *dctx, unused struct actitem *ti)
39 {
40 struct account *a = dctx->account;
41 struct mail *m = dctx->mail;
42
43 log_debug2("%s: writing to stdout", a->name);
44
45 if (fwrite(m->data, m->size, 1, stdout) != 1) {
46 log_warn("%s: fwrite", a->name);
47 return (DELIVER_FAILURE);
48 }
49
50 fflush(stdout);
51 return (DELIVER_SUCCESS);
52 }
53
54 void
deliver_stdout_desc(unused struct actitem * ti,char * buf,size_t len)55 deliver_stdout_desc(unused struct actitem *ti, char *buf, size_t len)
56 {
57 strlcpy(buf, "stdout", len);
58 }
59