aboutsummaryrefslogtreecommitdiff
#ifndef UTILITIES_H
#define UTILITIES_H

#include <stdbool.h>
#include <stdio.h>

#ifdef __cplusplus
#include "vmime/vmime.hpp"

vmime::shared_ptr<vmime::security::cert::defaultCertificateVerifier>
windows_root_certs_verifier(void);

extern "C" {
#endif

enum bool_param {
	PARAM_NO,
	PARAM_YES,
	PARAM_NOT_GIVEN
};

struct config {
	const char *host;
	const char *login;
	const char *password;
	const char *subject;
	const char *reply_to;
	const char *from;
	const char *dest_dir;
	const char **files;
	size_t nfiles;
	const char *msg_body;
	size_t msg_size;
	const char **to;
	size_t nto;
	int port_POP3;
	int port_SMTP;
	enum bool_param use_SSL;
	enum bool_param use_AUTH;
	int timeout;
	enum bool_param del_msgs;
	enum bool_param save_body;
	enum bool_param save_subj;
};

void _finish(bool ok);
#define PRINT_ERROR(message...) \
  ((fprintf(stderr, message) && false) || fprintf(stderr, "\r\n"))
#define FAIL(message...) _finish(PRINT_ERROR(message) && false)
#define FAIL_NOMSG() _finish(false)
#define SUCCEED() _finish(true)

void *dirtyalloc(size_t size);

void read_config(const char *filename, struct config *config);

void get_config(int argc, const char **argv, struct config *config);

int dummy_errback(const char *fmt, ...);

int provisional_wide_char_fgetc(FILE *stream);

bool is_valid_port_number(int port);

void free_config(struct config *config);

void validate_config(struct config *config);

void perform_work(const struct config *config);

inline static bool is_empty_string(const char *string)
{
	return string == NULL || *string == '\0';
}

#define MESSAGES_EXTERN
#include "messages.c"

#ifdef __cplusplus
}
#endif

#endif /* UTILITIES_H */