summaryrefslogtreecommitdiff
path: root/src/exporter.cpp
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@mailbox.org>2025-12-28 14:46:44 +0100
committerAldrik Ramaekers <aldrik@mailbox.org>2025-12-28 14:46:44 +0100
commitbe5c11029adb25c586c4fcde6fedfa01d1bdcd49 (patch)
tree251f196c59f5ce2625058c5788e2107059f642ef /src/exporter.cpp
parent7c3a271feea4b3693bf93a47924f7c682585e179 (diff)
email send backend
Diffstat (limited to 'src/exporter.cpp')
-rw-r--r--src/exporter.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/exporter.cpp b/src/exporter.cpp
new file mode 100644
index 0000000..c53b70d
--- /dev/null
+++ b/src/exporter.cpp
@@ -0,0 +1,69 @@
+/*
+* Copyright (c) 2025 Aldrik Ramaekers <aldrik.ramaekers@gmail.com>
+*
+* Permission to use, copy, modify, and/or distribute this software for any
+* purpose with or without fee is hereby granted, provided that the above
+* copyright notice and this permission notice appear in all copies.
+*
+* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+* ANY SPECIAL, DIRECT, 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.
+*/
+
+#include <threads.h>
+
+#define CPPHTTPLIB_OPENSSL_SUPPORT
+#include "httplib.h"
+#include "logger.hpp"
+#include "strops.hpp"
+#include "memops.hpp"
+#include "locales.hpp"
+#include "exporter.hpp"
+
+extern exporter::email_provider_impl _mailersend_api_provider;
+
+exporter::email_provider_impl exporter::get_email_provider_implementation(email_provider provider)
+{
+ switch(provider)
+ {
+ case EMAIL_PROVIDER_MAILERSEND: return _mailersend_api_provider;
+ default: assert(0); break;
+ }
+
+ return exporter::email_provider_impl {0};
+}
+
+static int _send_email_t(void* arg) {
+ exporter::export_request* request = (exporter::export_request*)arg;
+ request->status = exporter::status::EXPORT_WAITING_FOR_RESPONSE;
+
+ exporter::email_provider_impl impl = exporter::get_email_provider_implementation(administration::get_email_service().provider);
+ request->error = impl.send_email(request->sender, request->recipient, request->subject, request->text);
+
+ request->status = exporter::status::EXPORT_DONE;
+
+ return 0;
+}
+
+exporter::export_request* exporter::send_email(char* sender, char* recipient, const char* subject, const char* text)
+{
+ exporter::export_request* result = (exporter::export_request*)memops::alloc(sizeof(exporter::export_request));
+ result->started_at = time(NULL);
+ result->error = E_ERR_SUCCESS;
+ result->status = exporter::status::EXPORT_STARTING;
+ result->sender = sender;
+ result->recipient = recipient;
+ result->subject = subject;
+ result->text = text;
+
+ thrd_t thr;
+ if (thrd_create(&thr, _send_email_t, result) != thrd_success) {
+ return 0;
+ }
+
+ return result;
+} \ No newline at end of file