Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added documentation to the code

  • Loading branch information...
commit 17715d0c18f98bd85fa131cbfa78caacde8b5408 1 parent 0722c0d
@d0ugal d0ugal authored
Showing with 44 additions and 5 deletions.
  1. +44 −5 mailer.cpp
View
49 mailer.cpp
@@ -21,6 +21,7 @@
#include <User.h>
+// Forward de
class CMailerTimer: public CTimer {
public:
@@ -60,6 +61,12 @@ class CMailer : public CModule {
}
virtual bool OnLoad(const CString& sArgs, CString& sErrorMsg) {
+ /*
+ * On module load, check for debug being passed in as an arguement.
+ *
+ * Then setup the timer for batch emails and prompt the user for their
+ * email address.
+ */
VCString tokens;
int token_count = sArgs.Split(" ", tokens, false);
@@ -210,9 +217,15 @@ class CMailer : public CModule {
}
void Handle(CNick& Nick, const CString& location, CString& sMessage){
+ /*
+ * Method for handling all incoming messages that we are considering to
+ * email to the user. All private messages and all of those that
+ * SendNotification returns true for trigger an email.
+ */
if (SendNotification(Nick, sMessage) || location == "PRIVATE"){
+ // Build up a string containing the current time.
CString string_time;
time_t rawtime;
struct tm * timeinfo;
@@ -224,12 +237,16 @@ class CMailer : public CModule {
strftime (buffer,80,"(%x) %X",timeinfo);
string_time = buffer;
+ // Finally construct the message as it will be added to the email.
+ // and add it to a list (read queue) of messages to be sent.
CString message = string_time + ": <" + location + ":" + Nick.GetNick() + "> " + sMessage + "\n";
MessagesList.push_back(message);
DebugPrint("Added message...");
DebugPrint(message);
+ // Finally, check to see if we have the max number, and if we do,
+ // pop a message off the front to delete the oldest.
if (MessagesList.size() > MaxNotifications){
MessagesList.pop_front();
}
@@ -238,6 +255,12 @@ class CMailer : public CModule {
}
bool SendNotification(CNick& Nick, CString& sMessage){
+ /*
+ * Being passed in the nick name and the message, return true if an
+ * email notification should be sent to the user or not. At the moment
+ * this is a simple test that checks for a case insenstive username
+ * match which is a bit flawed as 1d0ugal1 still matches d0ugal.
+ */
// Don't send notifications if DebugMode is off and the ConnectedUser is not attached.
if (!DebugMode && ConnectedUser->IsUserAttached()){
@@ -257,10 +280,23 @@ class CMailer : public CModule {
}
void BatchSend(){
+ /*
+ * Job to send all of the email messages in the list queue.
+ */
DebugPrint("Preparing to batch send");
+ if (MessagesList.size() <= 0){
+ DebugPrint("No messages");
+ return;
+ }
+
if (!DebugMode && ConnectedUser->IsUserAttached()){
+ // There is a case, that if the user recieves a message, then
+ // conencts, there are some queue items waiting to be sent. Because
+ // we jump out early they are never cleared until they are sent
+ // when the user disconnects.
+ MessagesList.clear();
return;
}
@@ -268,11 +304,6 @@ class CMailer : public CModule {
CString message;
- if (MessagesList.size() <= 0){
- DebugPrint("No messages");
- return;
- }
-
for ( it=MessagesList.begin() ; it != MessagesList.end(); it++ ){
message = message + *it;
}
@@ -284,6 +315,11 @@ class CMailer : public CModule {
}
void Send(CString sMessage){
+ /*
+ * Wrapper to pipe the email body to the mail command. Fairly naieve
+ * about its purpose and will fail if it doesn't have a destination
+ * email or can't open the mail command (i.e. it isn't installed)
+ */
DebugPrint("Preparing to send email.");
@@ -318,6 +354,9 @@ class CMailer : public CModule {
};
void CMailerTimer::RunJob(){
+ /*
+ * Simple call to trigger the BatchSend method periodically.
+ */
CMailer *p = (CMailer *)m_pModule;
Please sign in to comment.
Something went wrong with that request. Please try again.