6 #include <sys/socket.h>
9 * This code is copyright 2001 by Craig Hughes
10 * Conversion to a thread-safe shared library copyright 2002 Liam Widdowson
11 * Portions copyright 2002 by Brad Jorsch
12 * It is licensed for use with SpamAssassin according to the terms of the
13 * Perl Artistic License
14 * The text of this license is included in the SpamAssassin distribution in
15 * the file named "License"
24 /* Aug 14, 2002 bj: Bitflags instead of lots of bool parameters */
25 #define SPAMC_MODE_MASK 1
26 #define SPAMC_RAW_MODE 0
27 #define SPAMC_BSMTP_MODE 1
29 #define SPAMC_SAFE_FALLBACK 1<<30
30 #define SPAMC_CHECK_ONLY 1<<31
32 /* Aug 14, 2002 bj: A struct for storing a message-in-progress */
42 /* Set before passing the struct on! */
43 int max_len; /* messages larger than this will return EX_TOOBIG */
45 /* Filled in by message_read */
47 char *raw; int raw_len; /* Raw message buffer */
48 char *pre; int pre_len; /* Pre-message data (e.g. SMTP commands) */
49 char *msg; int msg_len; /* The message */
50 char *post; int post_len; /* Post-message data (e.g. SMTP commands) */
52 /* Filled in by filter_message */
53 int is_spam; /* EX_ISSPAM if the message is spam, EX_NOTSPAM
54 if not, EX_TOOBIG if a filtered message is
55 returned in out below. */
56 float score, threshold; /* score and threshold */
57 char *out; int out_len; /* Output from spamd. Either the filtered
58 message, or the check-only response. Or else,
59 a pointer to msg above. */
62 /* Aug 14, 2002 bj: New interface functions */
64 /* Read in a message from the fd, with the mode specified in the flags.
65 * Returns EX_OK on success, EX_otherwise on failure. On failure, m may be
66 * either MESSAGE_NONE or MESSAGE_ERROR. */
67 int message_read(int in_fd, int flags, struct message *m);
69 /* Write out a message to the fd, as specified by m->type. Note that
70 * MESSAGE_NONE messages have nothing to write. Also note that if you ran the
71 * message through message_filter with SPAMC_CHECK_ONLY, it will only output
72 * the "score/threshold" line. */
73 long message_write(int out_fd, struct message *m);
75 /* Pass the message through spamd (at addr) as the specified user, with the
76 * given flags. Returns EX_OK on success, or various errors on error. If it was
77 * successful, message_write will print either the CHECK_ONLY output, or the
78 * filtered message in the appropriate output format. */
79 int message_filter(const struct sockaddr *addr, char *username, int flags, struct message *m);
81 /* Convert the host/port into a struct sockaddr. Returns EX_OK on success, or
82 * else an error EX. */
83 int lookup_host(const char *hostname, int port, struct sockaddr *a);
85 /* Dump the message. If there is any data in the message (typically, m->type
86 * will be MESSAGE_ERROR) it will be message_writed. Then, fd_in will be piped
87 * to fd_out intol EOF. This is particularly useful if you get back an
89 void message_dump(int in_fd, int out_fd, struct message *m);
91 /* Do a message_read->message_filter->message_write sequence, handling errors
92 * appropriately with dump_message or appropriate CHECK_ONLY output. Returns
93 * EX_OK or EX_ISSPAM/EX_NOTSPAM on success, some error EX on error. */
94 int message_process(const char *hostname, int port, char *username, int max_size, int in_fd, int out_fd, const int flags);
96 /* Cleanup the resources we allocated for storing the message. Call after
97 * you're done processing. */
98 void message_cleanup(struct message *m);
100 /* Aug 14, 2002 bj: This is now legacy, don't use it. */
101 int process_message(const char *hostname, int port, char *username,
102 int max_size, int in_fd, int out_fd,
103 const int check_only, const int safe_fallback);