BMAMail  1.0.0
E-Mail System
/home/bradarant/barant/BMAMail/__SMTP_DATA.h
Go to the documentation of this file.
1 #ifndef ____SMTP_DATA_h__
2 # define ____SMTP_DATA_h__
3 
4 # include "SMTPCommand.h"
5 
6 namespace mail {
7 
8  class __SMTP_DATA : public SMTPCommand {
9 
10  int processCommand(coreutils::PString request, SMTPSession &session, std::stringstream &data) {
11 
12  switch(session.mode) {
13 
14  case WAIT_FOR_DATA:
15 
16  switch(session.state) {
17 
18  case RCPT:
19  data << "354 Enter the mail message terminated by <CRLF>.<CRLF>" << CRLF;
20  session.mailData.str("");
21  session.mode = RECEIVE_DATA;
22  session.server.commands.grabInput(*this);
23  // setTimer(120.0f);
24  break;
25 
26  case MAIL:
27  data << "503 Please use RCPT first" << CRLF;
28  break;
29 
30  default:
31  data << "503 Please use MAIL first" << CRLF;
32  break;
33 
34  }
35  break;
36 
37  case RECEIVE_DATA:
38  session.mailData << request.str();
39  if(request.str().rfind("\r\n.\r\n") != std::string::npos) {
40  session.mode = WAIT_FOR_DATA;
41  session.state = READY;
42  session.server.commands.clearGrab();
43 // if(filterMessage(session.mailData)) {
44  if(session.recipientList.size() > 0) {
45  if(session.mailData.str().size() > 0) {
46  std::string ID = queueMail(session.sender, session.recipientList, session.mailData);
47  if(ID != "")
48  data << "250 OK Queued message " << ID << CRLF;
49  else
50  data << "550 Mail message too big" << CRLF;
51  } else
52  data << "550 Mail message was empty" << CRLF;
53  } else
54  data << "250 OK Queued message " << CRLF;
55 // } else
56 // data << "550 Message is probably spam" << CRLF;
57  }
58  break;
59  }
60  }
61 
62  std::string generateMailFileName() {
63  char name[256];
64  strftime(name, 256, "%Y%M%D%H%M%S", gmtime(time()));
65  return std::string(name);
66  }
67 
68  std::string queueMail(std::string sender, std::vector<std::string> recipientList, std::stringstream &mailData) {
69  std::string fileName = generateMailFileName();
70  coreutils::File mailFile(fileName, O_CREAT | O_WRONLY, 0660);
71  mailFile.write(mailData.str());
72 
73  for(std::string recipient: recipientList) {
74  std::string newName = fileName + recipient;
75  link(fileName, newName);
76  }
77 
78  unlink(fileName);
79 
80  return fileName;
81  }
82 
83  };
84 
85 }
86 
87 #endif
88 
Definition: SMTPSession.h:13
State state
Definition: SMTPSession.h:25
Definition: SMTPSession.h:11
Definition: SMTPSession.h:13
Definition: SMTPSession.h:11
std::vector< std::string > recipientList
Definition: SMTPSession.h:30
Mode mode
Definition: SMTPSession.h:27
Definition: __IMAP_APPEND.h:7
std::string sender
Definition: SMTPSession.h:29
Definition: SMTPCommand.h:9
#define CRLF
Definition: SMTPSession.h:7
Definition: SMTPSession.h:15
std::stringstream mailData
Definition: SMTPSession.h:24
Definition: __SMTP_DATA.h:8
Definition: SMTPSession.h:11