b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#ifndef SMTP_CLIENT_H
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#define SMTP_CLIENT_H
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#include "net.h"
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#include "smtp-common.h"
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#include "smtp-address.h"
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#include "smtp-reply.h"
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschstruct smtp_client;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschstruct smtp_client_request;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#define SMTP_DEFAULT_CONNECT_TIMEOUT_MSECS (1000*30)
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#define SMTP_DEFAULT_COMMAND_TIMEOUT_MSECS (1000*60*5)
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#define SMTP_DEFAULT_MAX_REPLY_SIZE ((size_t)-1)
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#define SMTP_DEFAULT_MAX_DATA_CHUNK_SIZE IO_BLOCK_SIZE
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#define SMTP_DEFAULT_MAX_DATA_CHUNK_PIPELINE 4
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschenum smtp_client_command_error {
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Server closed the connection */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_COMMAND_ERROR_CONNECTION_CLOSED = 421,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* The command was aborted */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_COMMAND_ERROR_ABORTED = 9000,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* DNS lookup failed */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_COMMAND_ERROR_HOST_LOOKUP_FAILED,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Failed to establish the connection */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_COMMAND_ERROR_CONNECT_FAILED,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Failed to authenticate using the provided credentials */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_COMMAND_ERROR_AUTH_FAILED,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Lost the connection after initially succeeded */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Got an invalid reply from the server */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_COMMAND_ERROR_BAD_REPLY,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* We sent a command with a payload stream that broke while reading
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch from it */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_COMMAND_ERROR_BROKEN_PAYLOAD,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* The server failed to respond before the command timed out */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch SMTP_CLIENT_COMMAND_ERROR_TIMED_OUT
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch};
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschstruct smtp_client_settings {
b136a381ac64c99b7341830ae664ae70c726c08fStephan Bosch struct ip_addr my_ip;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch const char *my_hostname;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch const char *temp_path_prefix;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch struct dns_client *dns_client;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch const char *dns_client_socket_path;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch const struct ssl_iostream_settings *ssl;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch const char *master_user;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch const char *username;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch const char *password;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch const struct dsasl_client_mech *sasl_mech;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Space-separated list of SASL mechanisms to try (in the specified
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch order). The default is to use only SASL PLAIN. */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch const char *sasl_mechanisms;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch const char *rawlog_dir;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Timeout for SMTP commands. Reset every time more data is being
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch sent or received.
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch (default = unlimited) */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch unsigned int command_timeout_msecs;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Timeout for loggging in
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch (default = cmd_timeout_msecs) */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch unsigned int connect_timeout_msecs;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Max total size of reply */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch size_t max_reply_size;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Maximum BDAT chunk size for the CHUNKING capability */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch uoff_t max_data_chunk_size;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* Maximum pipelined BDAT commands */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch unsigned int max_data_chunk_pipeline;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* if remote server supports XCLIENT capability,
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch send this data */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch struct smtp_proxy_data proxy_data;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* the kernel send/receive buffer sizes used for the connection sockets.
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch Configuring this is mainly useful for the test suite. The kernel
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch defaults are used when these settings are 0. */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch size_t socket_send_buffer_size;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch size_t socket_recv_buffer_size;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* enable logging debug messages */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch bool debug;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* peer is trusted, so e.g. attempt sending XCLIENT data */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch bool peer_trusted;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch /* don't clear password after first successful authentication */
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch bool remember_password;
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch};
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschstruct smtp_client *smtp_client_init(const struct smtp_client_settings *set);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschvoid smtp_client_deinit(struct smtp_client **_client);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Boschvoid smtp_client_switch_ioloop(struct smtp_client *client);
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch
b3888944586654b4aa069e0db31f998e0ed8b414Stephan Bosch#endif