plans and sketches
This commit is contained in:
70
email_parser/emailparser.cpp
Normal file
70
email_parser/emailparser.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include <email_parser/emailparser.h>
|
||||
|
||||
#include <utils/base64.h>
|
||||
#include <check/check.h>
|
||||
#include <boost/regex.hpp>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#if __GNUC__ < 8 && __clang_major__ < 17
|
||||
# include <experimental/filesystem>
|
||||
using namespace std::experimental::filesystem;
|
||||
#else
|
||||
# include <filesystem>
|
||||
using namespace std::filesystem;
|
||||
#endif
|
||||
|
||||
std::string EmailParser::get_payload_in_email(std::string &email_content) {
|
||||
boost::regex content_type_and_transfer_encoding_regex("Content-Type")
|
||||
// boost::regex body_start_regex("\r\n\r\n"); //boost::regex_constants::egrep
|
||||
// boost::smatch smatch;
|
||||
// if (boost::regex_search(email_content, smatch, body_start_regex)) {
|
||||
// return email_content.substr(smatch.position(), email_content.length());
|
||||
// }
|
||||
// return "";
|
||||
}
|
||||
|
||||
// std::vector<int> EmailParser::find_base64_blocks_in_email(std::string &email_content) {
|
||||
// std::string glued_together;
|
||||
// for (auto c : email_content) {
|
||||
// if (c == '\n') continue;
|
||||
// glued_together.push_back(c);
|
||||
// }
|
||||
// boost::regex base64_regex("^[-A-Za-z0-9+/]*={0,3}$");
|
||||
// }
|
||||
|
||||
|
||||
|
||||
EmailParser::EmailParser() {
|
||||
|
||||
}
|
||||
|
||||
Check EmailParser::parse(std::string &email_content) {
|
||||
//1. Search "Content-Type: image/.*" in the .eml file.
|
||||
// 1.1 If found 0, go to [2]
|
||||
// 1.2 If found 1, try decoding it, if it's not a QR code, go to [2]
|
||||
// 1.3 Loop through every found entry. If not found in any, go to [2]
|
||||
//2. Try decoding content of the e-mail
|
||||
//3. Search "t=\d{8}T\d{4,6}&s=\d{1,6}\.\d{1,2}&fn=\d{10,16}&i=\d{6}&fp=\d{10}&n=\d". Note that in some emails = and & signs could be replaced with its code in HTTP requests: %3D, %26
|
||||
// 3.1 If not found, notify the user that we could not parse the .eml file
|
||||
|
||||
|
||||
// std::string payload = get_payload_in_email(email_content);
|
||||
// Check c;
|
||||
|
||||
// std::cout << payload << std::endl;
|
||||
|
||||
// if (payload == "")
|
||||
// return c;
|
||||
|
||||
|
||||
|
||||
// return c;
|
||||
}
|
||||
|
||||
Check EmailParser::parse_file(std::string path) {
|
||||
std::ifstream ifile(path, std::ios::in | std::ios::binary);
|
||||
const unsigned int size = std::filesystem::file_size(path);
|
||||
std::string content(size, '\0');
|
||||
ifile.read(content.data(), size);
|
||||
return parse(content);
|
||||
}
|
||||
15
email_parser/emailparser.h
Normal file
15
email_parser/emailparser.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef CHECKS_PARSER_EMAIL_PARSER
|
||||
#define CHECKS_PARSER_EMAIL_PARSER
|
||||
|
||||
#include <check/check.h>
|
||||
|
||||
class EmailParser {
|
||||
std::string get_payload_in_email(std::string &email_content);
|
||||
// std::vector<int> find_base64_blocks_in_email(std::string &email_content);
|
||||
public:
|
||||
EmailParser();
|
||||
Check parse(std::string &email_content);
|
||||
Check parse_file(std::string path);
|
||||
};
|
||||
|
||||
#endif // CHECKS_PARSER_EMAIL_PARSER
|
||||
Reference in New Issue
Block a user