<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>src/log/ConversationDebug.cpp</filename>
    </added>
    <added>
      <filename>src/log/ConversationDebug.h</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,7 +1,7 @@
 include_directories(/usr/include/mysql)
 link_directories(/usr/lib/)
 
-add_executable(scopeport-server core.cc host/Host.cpp database/Database.cpp database/Information.cpp health/Health.cpp log/Log.cpp misc/Timer.cpp notifications/Clickatell.cpp notifications/EmergencyNotifications.cpp notifications/GeneralNotifications.cpp notifications/Mail.cpp notifications/Warning.cpp notifications/XMPP.cpp services/Services.cpp cloud/Cloud.cpp)
+add_executable(scopeport-server core.cc host/Host.cpp database/Database.cpp database/Information.cpp health/Health.cpp log/Log.cpp misc/Timer.cpp notifications/Clickatell.cpp notifications/EmergencyNotifications.cpp notifications/GeneralNotifications.cpp notifications/Mail.cpp notifications/Warning.cpp notifications/XMPP.cpp services/Services.cpp cloud/Cloud.cpp log/ConversationDebug.cpp)
 
 add_definitions(-O3 -Wall)
 </diff>
      <filename>src/CMakeLists.txt</filename>
    </modified>
    <modified>
      <diff>@@ -553,7 +553,7 @@ void* onlineStateChecks(void* arg){
 
 								// Get mail receivers and send warnings.
 								if(mailData.doMailing){
-									Mail mailing(mailData);
+									Mail mailing(mailData, dbData);
 									vector&lt;string&gt; mailRecvList;
 									mailRecvList = Information::getMailWarningReceivers(db.getHandle(),
 																db.sGetQuery(Information::getReceiverGroup(row[0], &quot;0&quot;)),
@@ -593,7 +593,7 @@ void* onlineStateChecks(void* arg){
 											db.sGetQuery(Information::getReceiverGroup(row[0],&quot;0&quot;)),
 											db.sGetQuery(Information::getSensorSeverity(row[0], &quot;0&quot;)));
 
-									Mail mailing(mailData);
+									Mail mailing(mailData, dbData);
 									int mobilecRecvCount = 0;
 									int mobilecRecvListSize = mobilecRecvList.size();
 									while(mobilecRecvCount &lt; mobilecRecvListSize){</diff>
      <filename>src/core.cc</filename>
    </modified>
    <modified>
      <diff>@@ -173,4 +173,10 @@ bool numOnly(string checkMe);
 #define SERVICE_STATE_INTERR -1
 #define SERVICE_STATE_TIMEOUT 4
 
+// Conversation debugging
+#define CONV_DEBUG_DIRECTION_SENT 0
+#define CONV_DEBUG_DIRECTION_RECV 1
+#define CONV_DEBUG_ERROR_SENT &quot;Sending the message failed&quot;
+#define CONV_DEBUG_ERROR_RECV &quot;Nothing was received&quot;
+
 #endif /*INTERNAL_H_*/</diff>
      <filename>src/internal.h</filename>
    </modified>
    <modified>
      <diff>@@ -204,13 +204,13 @@ int EmergencyNotifications::sendMessage(int recvNum){
 		return 1;
 	}else if(info.type == &quot;mail&quot;){
 		// We need to send an email.
-		Mail mailing(mailData);
+		Mail mailing(mailData, dbData);
 		if(!mailing.sendMail(info.address, &quot;An emergency has been declared&quot;, message.str()))
 			return -1;
 		return 1;
 	}else if(info.type == &quot;mobilec&quot;){
 		// We need to send an SMS via the Clickatell SMTP API.
-		Mail mailing(mailData);
+		Mail mailing(mailData, dbData);
 		// Build the message that fits to the API.
 		stringstream newMessage;
 		newMessage	&lt;&lt; &quot;user:&quot; &lt;&lt; clickatellData.username &lt;&lt; endl</diff>
      <filename>src/notifications/EmergencyNotifications.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -78,7 +78,7 @@ bool GeneralNotifications::sendMessages(string subject, string message){
 	if(!fallback &amp;&amp; initConnection()){
 		MYSQL* init = getHandle();
 
-		Mail mailing(mailData);
+		Mail mailing(mailData, dbData);
 
 		XMPP xmpp(xmppData, dbData);
 
@@ -142,7 +142,7 @@ bool GeneralNotifications::sendMessages(string subject, string message){
 		
 		message = message + &quot; (This message has been sent in fallback mode!)&quot;;
 		if(mailData.doMailing){
-			Mail mailing(mailData);
+			Mail mailing(mailData, dbData);
 			mailing.sendMail(mailData.fallbackReceiver, subject, message);
 		}
 		
@@ -152,7 +152,7 @@ bool GeneralNotifications::sendMessages(string subject, string message){
 		}
 		
 		if(clickatellData.doMobileC &amp;&amp; mailData.doMailing){
-			Mail mailing(mailData);
+			Mail mailing(mailData, dbData);
 			// Build the message that fits to the API.  
 			stringstream newWarningMsg;
 			newWarningMsg	&lt;&lt; &quot;user:&quot; &lt;&lt; clickatellData.username &lt;&lt; endl</diff>
      <filename>src/notifications/GeneralNotifications.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -19,8 +19,9 @@
 #include &quot;../internal.h&quot;
 #include &quot;../database/Database.h&quot;
 
-Mail::Mail(mailingData myMailData){
+Mail::Mail(mailingData myMailData, mySQLData myDBData){
 	mailData = myMailData;
+  dbData = myDBData;
 }
 
 void Mail::updateSettings(mailingData myMailData){
@@ -29,22 +30,34 @@ void Mail::updateSettings(mailingData myMailData){
 
 int sock;
 
-bool send_socket(string msg){
+bool Mail::sendSocket(string msg){
 	ssize_t len;
 	len = write(sock,msg.c_str(),strlen(msg.c_str()));
-	if(len &lt;= 0)
+	if(len &lt;= 0){
+    p_debug-&gt;log(CONV_DEBUG_DIRECTION_SENT, CONV_DEBUG_ERROR_SENT);
 		return 0;
+  }
+  p_debug-&gt;log(CONV_DEBUG_DIRECTION_SENT, noNewLineS(msg));
 	return 1;
 }
 
 #define MAILBUFSIZE 1024
 
-bool read_socket(){
+bool Mail::readSocket(){
 	ssize_t len;
-	char mailBuf[MAILBUFSIZE];
+	char mailBuf[MAILBUFSIZE] = &quot;&quot;;
 	len = read(sock,mailBuf, MAILBUFSIZE-1);
-	if(len &lt;= 0)
+  
+	if(len &lt;= 0){
+    p_debug-&gt;log(CONV_DEBUG_DIRECTION_RECV, CONV_DEBUG_ERROR_RECV);
 		return 0;
+  }
+
+  // Terminate the buffer.
+  mailBuf[MAILBUFSIZE-1] = '\0';
+
+  p_debug-&gt;log(CONV_DEBUG_DIRECTION_RECV, noNewLine(mailBuf, strlen(mailBuf)));
+
 	return 1;
 }
 
@@ -142,10 +155,13 @@ bool Mail::sendMail(string toMail, string subject, string mailText){
 		return 0;
 	}
 
-	// A little bit Conversation.
+	// A little bit conversation.
+  
+  ConversationDebug debug(dbData, &quot;smtp&quot;, mailData.mailServer);
+  p_debug = &amp;debug;
 
 	// Welcome string.
-	if(!read_socket())
+	if(!readSocket())
 		return 0;
 
 	if(mailData.mailUseAuth){
@@ -155,29 +171,29 @@ bool Mail::sendMail(string toMail, string subject, string mailText){
 				&lt;&lt; mailData.mailHostname
         &lt;&lt; &quot;\r\n&quot;;
 
-		if(!send_socket(ehlo.str()))
+		if(!sendSocket(ehlo.str()))
 			return 0;
 		// Get reply.
-		if(!read_socket())
+		if(!readSocket())
 			return 0;
 		// Ask for AUTH LOGIN.
-		if(!send_socket(&quot;AUTH LOGIN\r\n&quot;))
+		if(!sendSocket(&quot;AUTH LOGIN\r\n&quot;))
 			return 0;
-		if(!read_socket())
+		if(!readSocket())
 			return 0;
 		// Send username.
-		if(!send_socket(encodeBase64(mailData.mailUser)))
+		if(!sendSocket(encodeBase64(mailData.mailUser)))
 			return 0;
-		if(!send_socket(&quot;\r\n&quot;))
+		if(!sendSocket(&quot;\r\n&quot;))
 			return 0;
-		if(!read_socket())
+		if(!readSocket())
 			return 0;
 		// Send Password.
-		if(!send_socket(encodeBase64(mailData.mailPass)))
+		if(!sendSocket(encodeBase64(mailData.mailPass)))
 			return 0;
-		if(!send_socket(&quot;\r\n&quot;))
+		if(!sendSocket(&quot;\r\n&quot;))
 			return 0;
-		if(!read_socket())
+		if(!readSocket())
 			return 0;
 	}else{
 		// HELO.
@@ -186,10 +202,10 @@ bool Mail::sendMail(string toMail, string subject, string mailText){
 				&lt;&lt; mailData.mailHostname
         &lt;&lt; &quot;\r\n&quot;;
 
-		if(!send_socket(helo.str()))
+		if(!sendSocket(helo.str()))
 			return 0;
 		// Get reply.
-		if(!read_socket())
+		if(!readSocket())
 			return 0;
 	}
 
@@ -199,9 +215,9 @@ bool Mail::sendMail(string toMail, string subject, string mailText){
 				&lt;&lt; mailData.mailFrom
 				&lt;&lt; &quot;&gt;\r\n&quot;;
 
-	if(!send_socket(mailFrom.str()))
+	if(!sendSocket(mailFrom.str()))
 		return 0;
-	if(!read_socket())
+	if(!readSocket())
 		return 0;
 
 	// Recipient.
@@ -210,15 +226,15 @@ bool Mail::sendMail(string toMail, string subject, string mailText){
 				&lt;&lt; toMail
 				&lt;&lt; &quot;&gt;\r\n&quot;;
 
-	if(!send_socket(mailTo.str()))
+	if(!sendSocket(mailTo.str()))
 		return 0;
-	if(!read_socket())
+	if(!readSocket())
 		return 0;
 
 	// Data.
-	if(!send_socket(&quot;DATA\r\n&quot;))
+	if(!sendSocket(&quot;DATA\r\n&quot;))
 		return 0;
-	if(!read_socket())
+	if(!readSocket())
 		return 0;
 
 	// Header.
@@ -226,35 +242,35 @@ bool Mail::sendMail(string toMail, string subject, string mailText){
 	headerTo	&lt;&lt; &quot;to: &quot;
 				&lt;&lt; toMail
         &lt;&lt; &quot;\r\n&quot;;
-	if(!send_socket(headerTo.str()))
+	if(!sendSocket(headerTo.str()))
 		return 0;
 
 	stringstream headerFrom;
 	headerFrom	&lt;&lt; &quot;from: &quot;
 				&lt;&lt; mailData.mailFrom
         &lt;&lt; &quot;\r\n&quot;;
-	if(!send_socket(headerFrom.str()))
+	if(!sendSocket(headerFrom.str()))
 		return 0;
 
 	stringstream headerSubject;
 	headerSubject	&lt;&lt; &quot;subject: [ScopePort] &quot;
 					&lt;&lt; subject
 					&lt;&lt; &quot;\r\n\r\n&quot;;
-	if(!send_socket(headerSubject.str()))
+	if(!sendSocket(headerSubject.str()))
 		return 0;
-	if(!send_socket(mailText))
+	if(!sendSocket(mailText))
 		return 0;
-	if(!send_socket(&quot;\n\n.\n&quot;))
+	if(!sendSocket(&quot;\n\n.\n&quot;))
 		return 0;
 
 	// Quit.
-	if(!read_socket())
+	if(!readSocket())
 		return 0;
 
-	if(!send_socket(&quot;QUIT\r\n&quot;))
+	if(!sendSocket(&quot;QUIT\r\n&quot;))
 		return 0;
 
-	if(!read_socket())
+	if(!readSocket())
 		return 0;
 
 	// Close socket.</diff>
      <filename>src/notifications/Mail.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 // This file is part of ScopePort (Linux server).
 //
-// Copyright 2008 Lennart Koopmann
+// Copyright 2008, 2009 Lennart Koopmann
 //
 // ScopePort (Linux server) is free software: you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as published by
@@ -25,13 +25,20 @@
 #define MAIL_H_
 
 #include &quot;../internal.h&quot;
+#include &quot;../log/ConversationDebug.h&quot;
 
 class Mail{
 	private:
 		//! Holds login, server and general SMTP information.
 		mailingData mailData;
+    mySQLData dbData;
+
+    ConversationDebug* p_debug;
+
+    bool readSocket();
+    bool sendSocket(string msg);
 	public:
-		Mail(mailingData myMailData);
+		Mail(mailingData myMailData, mySQLData myDBData);
 		//! Updates mailData
 		/*!
 		 * \sa mailData</diff>
      <filename>src/notifications/Mail.h</filename>
    </modified>
    <modified>
      <diff>@@ -334,7 +334,7 @@ void Services::sendWarning(){
 		mobilecData = Clickatell::fetchSettings(dbData);
 
 		// Create mailing object.
-		Mail mailing(mailData);
+		Mail mailing(mailData, dbData);
 
 		// Check for mailing parameters.
 		if(mailData.doMailing &amp;&amp; !mailData.mailServer.empty() &gt; 0 &amp;&amp; mailData.mailPort &gt; 0</diff>
      <filename>src/services/Services.cpp</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d70dd5cb663d2f44e90c534e9e0476eec6e04b90</id>
    </parent>
  </parents>
  <author>
    <name>lennartkoopmann</name>
    <login>lennartkoopmann</login>
    <email>lennart@scopeport.org</email>
  </author>
  <url>http://github.com/lennartkoopmann/scopeport-server/commit/6bcf90012233430953387e3b6ad75ec521ad28d5</url>
  <id>6bcf90012233430953387e3b6ad75ec521ad28d5</id>
  <committed-date>2009-06-28T16:33:51-07:00</committed-date>
  <authored-date>2009-06-28T16:33:51-07:00</authored-date>
  <message>Now storing SMTP conversations in an own log table</message>
  <tree>ae7f37c5f7bdf6be796075005f2c62e263a8f50a</tree>
  <committer>
    <name>lennartkoopmann</name>
    <login>lennartkoopmann</login>
    <email>lennart@scopeport.org</email>
  </committer>
</commit>
