File: smtpclient.h

package info (click to toggle)
cyrus-imapd 3.6.1-4%2Bdeb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,688 kB
  • sloc: ansic: 255,928; perl: 97,730; javascript: 9,266; sh: 5,537; yacc: 2,651; cpp: 2,128; makefile: 2,099; lex: 660; xml: 621; python: 388; awk: 303; asm: 262
file content (184 lines) | stat: -rw-r--r-- 7,285 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/* smtpclient.h -- Routines for sending a message via SMTP
 *
 * Copyright (c) 1994-2008 Carnegie Mellon University.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The name "Carnegie Mellon University" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For permission or any legal
 *    details, please contact
 *      Carnegie Mellon University
 *      Center for Technology Transfer and Enterprise Creation
 *      4615 Forbes Avenue
 *      Suite 302
 *      Pittsburgh, PA  15213
 *      (412) 268-7393, fax: (412) 268-7395
 *      innovation@andrew.cmu.edu
 *
 * 4. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by Computing Services
 *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
 *
 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef INCLUDED_SMTPCLIENT_H
#define INCLUDED_SMTPCLIENT_H

#include "prot.h"
#include "ptrarray.h"
#include "strarray.h"
#include "util.h"

/* A parameter for SMTP envelope address, identified by key.
 * The value val may be NULL. */
typedef struct {
    char *key;
    char *val;
} smtp_param_t;

/* A SMTP envelope address with address addr. The params
 * array contains the optional address parameters for the
 * MAIL FROM and RCPT TO commands. */
typedef struct {
    char *addr;
    ptrarray_t params; /* Array of smtp_param_t */
    int completed;
} smtp_addr_t;

/* A SMTP envelope with the MAIL FROM address and one
 * or more RCPT TO recipient addresses. */
typedef struct {
    smtp_addr_t from;
    ptrarray_t rcpts; /* Array of smtp_addr_t */
} smtp_envelope_t;

/* The empty SMTP envelope */
#define SMTP_ENVELOPE_INITIALIZER { { NULL, PTRARRAY_INITIALIZER, 0 }, PTRARRAY_INITIALIZER }

/* Return non-zero if val is a valid esmtp-keyword
 * as defined in RFC 5321, section 4.1.2. */
extern int smtp_is_valid_esmtp_keyword(const char *val);

/* Return non-zero if val is a valid esmtp-value
 * as defined in RFC 5321, section 4.1.2. */
extern int smtp_is_valid_esmtp_value(const char *val);

/* Encode val as an esmtp-value
 * as defined in RFC 5321, section 4.1.2. */
extern void smtp_encode_esmtp_value(const char *val, struct buf *xtext);

/* Set the MAIL FROM address in env and return the new value.
 * Any existing address is deallocated. */
extern smtp_addr_t *smtp_envelope_set_from(smtp_envelope_t *env, const char *addr);

/* Add a RCPT TO address to the recipients of env and return the new value. */
extern smtp_addr_t *smtp_envelope_add_rcpt(smtp_envelope_t *env, const char *addr);

/* Free all memory of pointers and arrays in env */
extern void smtp_envelope_fini(smtp_envelope_t *env);

/* Opaque SMTP client type */
typedef struct smtpclient smtpclient_t;

/* Open a SMTP client to the default SMTP backend */
extern int smtpclient_open(smtpclient_t **smp);

/* Open a SMTP client to the sendmail process */
extern int smtpclient_open_sendmail(smtpclient_t **smp);

/* Open a SMTP client to the host at addr, formatted as host[:port] */
extern int smtpclient_open_host(const char *addr, smtpclient_t **smp);

/* Send message data with SMTP envelope env. Data is dot-escaped
 * before it is written to the SMTP backend. */
extern int smtpclient_send(smtpclient_t *sm, smtp_envelope_t *env, struct buf *data);
extern int smtpclient_sendprot(smtpclient_t *sm, smtp_envelope_t *env, struct protstream *data);

/* Check the SMTP envelope (and optionally size and/or From: header addresses)
   without sending data */
extern int smtpclient_sendcheck(smtpclient_t *sm, smtp_envelope_t *env,
                                size_t size, strarray_t *fromaddr);

/* Close the SMTP client and free its memory */
extern int smtpclient_close(smtpclient_t **smp);

/* Add the AUTH=userid parameter to MAIL FROM commands, if the
 * SMTP backend advertised support for the RFC 4954 AUTH extension.
 *
 * An AUTH parameter in the SMTP envelope of the smtpclient_send
 * function overrides this value, regardless of advertised extensions.
 *
 * Setting this to NULL resets userid. */
extern void smtpclient_set_auth(smtpclient_t *sm, const char *userid);

/* Add the NOTIFY=value parameter to RCPT TO commands, if the
 * SMTP backend advertised support for the RFC 3461 DSN extension.
 *
 * A NOTIFY parameter in the SMTP envelope of the smtpclient_send
 * function overrides this value, regardless of advertised extensions.
 *
 * Setting this to NULL resets the value. */
extern void smtpclient_set_notify(smtpclient_t *sm, const char *value);

/* Add the RET=value parameter to MAIL FROM commands, if the
 * SMTP backend advertised support for the RFC 3461 DSN extension.
 *
 * A RET parameter in the SMTP envelope of the smtpclient_from
 * function overrides this value, regardless of advertised extensions.
 *
 * Setting this to NULL resets the value. */
extern void smtpclient_set_ret(smtpclient_t *sm, const char *value);

/* Add the BY=value parameter to MAIL FROM commands, if the
 * SMTP backend advertised support for the RFC 2852 DELIVERYBY extension.
 *
 * A BY parameter in the SMTP envelope of the smtpclient_from
 * function overrides this value, regardless of advertised extensions.
 *
 * Setting this to NULL resets the value. */
extern void smtpclient_set_by(smtpclient_t *sm, const char *value);

/* Add the SIZE=value parameter to MAIL FROM commands, if the
 * SMTP backend advertised support for the RFC 1870 SIZE extension.
 *
 * A SIZE parameter in the SMTP envelope of the smtpclient_from
 * function overrides this value, regardless of advertised extensions.
 *
 * Setting this to 0 resets the value. */
extern void smtpclient_set_size(smtpclient_t *sm, unsigned long value);

/* Return the SIZE SMTP extension value.
 *
 * Return 0 if the extension has no value or is not supported. */
extern unsigned long smtpclient_get_maxsize(smtpclient_t *sm);

/* Return the argument string of SMTP extension 'name' as returned
 * in response to the EHLO command, excluding the extension name.
 * This may be the empty string.
 * Return NULL if the extension is not supported. */
extern const char *smtpclient_has_ext(smtpclient_t *sm, const char *name);

/* Return the text of the last SMTP response */
extern const char *smtpclient_get_resp_text(smtpclient_t *sm);


#endif