|
#include
#include
#include
#include
#include
#include
#pragma comment(lib, "ws2_32.lib")
#define MAKE_INT32(str) \
(static_cast(str[0]) ', start);
if (start != std::string::npos && end != std::string::npos) {
return command.substr(start + 1, end - start - 1);
}
return "";
}
std::string parseRecipient(const std::string& command) {
std::size_t start = command.find('', start);
if (start != std::string::npos && end != std::string::npos) {
return command.substr(start + 1, end - start - 1);
}
return "";
}
bool createFolder(const std::string& folderPath) {
try {
fs::create_directory(folderPath);
return true;
}
catch (const std::exception& e) {
std::cerr = 4)
{
switch (MAKE_INT32(command))
{
case MAKE_INT32("MAIL"):
// 收到 MAIL FROM 命令,获取发件人信息
sender = parseSender(command);
break;
// 判断下一个命令是否为 RCPT TO
case MAKE_INT32("RCPT"):
// 获取收件人信息
recipient = parseRecipient(command);
break;
//const std::string welcomeMessage = "250 OK\r\n";
//send(clientSocket, welcomeMessage.c_str(), welcomeMessage.size(), 0);
// 接收下一个命令
// 判断下一个命令是否为 DATA
case MAKE_INT32("DATA"):
// 发送接收数据的响应
std::string dataResponse = "354 Start mail input; end with .\r\n";
send(clientSocket, dataResponse.c_str(), static_cast(dataResponse.size()), 0);
// 接收邮件内容
std::string emailContent;
while (true) {
char buffer[BUFFER_SIZE];
int bytesRead = recv(clientSocket, buffer, BUFFER_SIZE - 1, 0);
if (bytesRead = 5 && emailContent.substr(emailContent.length() - 5) == "\r\n.\r\n") {
break;
}
}
// 保存邮件到文件
saveEmailToFile(emailContent, sender, recipient);
break;
case MAKE_INT32("QUIT"):
break;
default:
break;
}
// 发送接收成功的响应
std::string response = "250 OK\r\n";
send(clientSocket, response.c_str(), static_cast(response.size()), 0);
if (!receiveCommand(clientSocket, command)) {
std::cerr
wise指南 发表于 2023-6-9 16:50
这个怎么解析mime呢?
邮件不都是纯plain的呀。
不知道,反正邮件以源文件保存到txt文件了,解析更多内容需要继续对gpt进行拷问才行,问了至少6个小时才给我这么点东西,不过测试确实能收邮件 |
|