summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/MailServer.h10
-rw-r--r--lib/MailServer.cc10
2 files changed, 15 insertions, 5 deletions
diff --git a/include/MailServer.h b/include/MailServer.h
index df1f83a..e39ad93 100644
--- a/include/MailServer.h
+++ b/include/MailServer.h
@@ -28,9 +28,16 @@
#include <Exceptions.h>
#include <Variables.h>
+class MailHandler : public Base {
+ public:
+ MailHandler() {}
+ virtual ~MailHandler() {}
+ virtual void ProcessMail(Handle * in, const String & from, std::vector<String> tos) = 0;
+};
+
class MailServer : public Task {
public:
- MailServer(int = 2500, const String & = String("GruiK Server v0.2")) throw (GeneralException);
+ MailServer(MailHandler *, int = 2500, const String & = String("GruiK Server v0.2")) throw (GeneralException);
virtual ~MailServer();
virtual String GetName();
@@ -41,6 +48,7 @@ class MailServer : public Task {
Socket Listener;
String name;
int localport;
+ MailHandler * handler;
};
#endif
diff --git a/lib/MailServer.cc b/lib/MailServer.cc
index b34678e..d0bb165 100644
--- a/lib/MailServer.cc
+++ b/lib/MailServer.cc
@@ -31,7 +31,7 @@ const timeval timeout_sending = { 80, 0 };
class ProcessSMTPRequest : public Task {
public:
- ProcessSMTPRequest(const Socket & out) : s(out) {
+ ProcessSMTPRequest(const Socket & out, MailHandler * _handler) : s(out), handler(_handler) {
SetBurst();
}
virtual ~ProcessSMTPRequest() {
@@ -47,6 +47,7 @@ class ProcessSMTPRequest : public Task {
Task * c;
String from;
std::vector<String> tos;
+ MailHandler * handler;
};
static Regex single_dot("^\\.$"), dotted_line("^\\..+$");
@@ -158,7 +159,8 @@ int ProcessSMTPRequest::Do() {
}
}
- // do something with out
+ if (handler)
+ handler->ProcessMail(out, from, tos);
delete out;
@@ -174,7 +176,7 @@ int ProcessSMTPRequest::Do() {
}
}
-MailServer::MailServer(int _port, const String & _name) throw (GeneralException) : name(_name), localport(_port) {
+MailServer::MailServer(MailHandler * _handler, int _port, const String & _name) throw (GeneralException) : name(_name), localport(_port), handler(_handler) {
bool r;
r = Listener.SetLocal("", localport);
@@ -200,7 +202,7 @@ int MailServer::Do() throw (GeneralException) {
try {
Socket s = Listener.Accept();
s.SetNonBlock();
- new ProcessSMTPRequest(s);
+ new ProcessSMTPRequest(s, handler);
}
catch (GeneralException) {
}