This commit is contained in:
2022-02-10 01:37:43 +01:00
parent eef34d8d9d
commit 1698a2ecb8
10 changed files with 422 additions and 77 deletions

View File

@ -89,7 +89,7 @@ kaz::operator << (ostream& os, const EmbeddedData& embeddedData) {
os << embeddedData.imgIdx << ": "
<< embeddedData.contentType << " - " << embeddedData.name
<< " (" << embeddedData.startData << " / " << embeddedData.dataLength << ") "
<< embeddedData.downloadUrl << " - " << embeddedData.downloadId
<< embeddedData.downloadUrl
<< endl;
return os;
}

View File

@ -124,18 +124,28 @@ MainAttachment::copy (ifstream &mbox, ofstream &outbox, const streamoff &begin,
// ================================================================================
void
MainAttachment::fillUrlId (string &url, string &id) {
DEF_LOG ("MainAttachment::fillUrlId", "");
url = id = "";
string urlId;
getline (cin, urlId);
LOG ("get URL: " << urlId);
vector<string> urlIdVect { sregex_token_iterator (urlId.begin(), urlId.end (), whiteSpaceRegEx, -1), {} };
if (urlIdVect [0].empty ())
MainAttachment::readArchiveUrl () {
DEF_LOG ("MainAttachment::readArchiveUrl", "");
archiveDownloadURL.clear ();
string line;
getline (cin, line);
LOG_BUG (line.rfind ("arch: ", 0) != 0, return, "eMailShrinker: bug ZZ: no archive link. (line: " << line << ")");
LOG_BUG (line.rfind ("arch: bad", 0) == 0, return, "eMailShrinker: bug ZZ: bad archive link. (line: " << line << ")");
if (line.rfind ("arch: none", 0) == 0)
return;
url = urlIdVect [0];
if (urlIdVect.size () > 1)
id = urlIdVect [1];
archiveDownloadURL = line.substr (6);
}
// ================================================================================
void
MainAttachment::readDownloadUrl (string &url) {
DEF_LOG ("MainAttachment::readDownloadUrl", "");
url = "";
string line;
getline (cin, line);
LOG ("get URL: " << line);
LOG_BUG (line.rfind ("url: ", 0) != 0, return, "eMailShrinker: bug ZZ: no download link. (line: " << line << ")");
url = line.substr (5);
}
// ================================================================================
@ -148,11 +158,6 @@ MainAttachment::setExtractDir (const bfs::path &extractDir) {
bfs::create_directory (extractDir);
}
void
MainAttachment::setArchiveDownloadURL (const string &archiveDownloadURL) {
this->archiveDownloadURL = archiveDownloadURL;
}
// ================================================================================
void
MainAttachment::addLink (string &plain, string &html, const string &url, const string &name) const {
@ -175,14 +180,12 @@ MainAttachment::getDisclaim (string &plain, string &html) const {
plain = html = "";
int linkCount (0);
string allId;
string plainNewLinks, htmlNewLinks;
for (Attachment *attachP : allMarkedPtrs) {
if (!attachP->toExtract)
continue;
addLink (plainNewLinks, htmlNewLinks, attachP->downloadUrl, attachP->getAttachName ());
++linkCount;
allId += attachP->downloadId;
// if (previousLinks [attachP->downloadUrl] != previousLinks.end ())
// // impossible puisque le lien est toujours nouveau
// previousLinks.erase (attachP->downloadUrl);
@ -193,10 +196,8 @@ MainAttachment::getDisclaim (string &plain, string &html) const {
for (EmbeddedData &embedded : attachP->embeddedData) {
addLink (plainNewLinks, htmlNewLinks, embedded.downloadUrl, embedded.name);
++linkCount;
allId += embedded.downloadId;
}
}
LOG ("allId:" << allId);
string plainOldLinks, htmlOldLinks;
for (map <string, string>::const_iterator it = previousLinks.begin (); it != previousLinks.end (); ++it)
@ -215,11 +216,10 @@ MainAttachment::getDisclaim (string &plain, string &html) const {
}
if (linkCount > 1 && archiveDownloadURL.length ()) {
string allPlainLinks (templatePlainAllLink);
replaceAll (allPlainLinks, TMPL_DOWNLOAD, archiveDownloadURL+allId);
replaceAll (allPlainLinks, TMPL_DOWNLOAD, archiveDownloadURL);
plain += allPlainLinks;
string allLinks (templateHtmlAllLink);
// allId => & => &amp; done
replaceAll (allLinks, TMPL_DOWNLOAD, archiveDownloadURL+allId);
replaceAll (allLinks, TMPL_DOWNLOAD, archiveDownloadURL);
html += allLinks;
}
html += templateHtmlFooter;
@ -503,7 +503,7 @@ MainAttachment::substitute (ifstream &mbox, ofstream &outbox, const SizeArg &min
map<const string, const string> translateHtml;
for (Attachment *attachP : allMarkedPtrs)
if (attachP->toExtract) {
fillUrlId (attachP->downloadUrl, attachP->downloadId);
readDownloadUrl (attachP->downloadUrl);
if (attachP->downloadUrl.empty ()) {
LOG ("no change");
attachP->toExtract = false;
@ -519,8 +519,9 @@ MainAttachment::substitute (ifstream &mbox, ofstream &outbox, const SizeArg &min
if (!attachP->embeddedData.size ())
continue;
for (EmbeddedData &embedded : attachP->embeddedData)
fillUrlId (embedded.downloadUrl, embedded.downloadId);
readDownloadUrl (embedded.downloadUrl);
}
readArchiveUrl ();
string plainDisclaim, htmlDisclaim;
getDisclaim (plainDisclaim, htmlDisclaim);
// copy email

View File

@ -32,7 +32,7 @@
// knowledge of the CeCILL-B license and that you accept its terms. //
////////////////////////////////////////////////////////////////////////////
#define LAST_VERSION "eMailShrinker 1.4 2021-05-07"
#define LAST_VERSION "2.0 2022-02-08 eMailShrinker"
#include <iostream>
#include <fstream>
@ -67,7 +67,7 @@ usage (const string &msg = "", const bool &hidden = false) {
<< "Usage: " << endl
<< " A) " << prog << " -u mbox > url-list" << endl
<< " B) " << prog << " [-s size] [-d dirName}] mbox > file-list" << endl
<< " C) " << prog << " [-s size] [-a url] mbox altered-mbox < url-list" << endl
<< " C) " << prog << " [-s size] mbox altered-mbox < url-list" << endl
<< endl << " filter attachments" << endl << endl
<< " A: list previous embded url need to be refresh (no added option)" << endl
<< " => downloadURL list" << endl
@ -114,7 +114,7 @@ main (int argc, char** argv) {
updateListFlag (false),
useTheForceLuke (false),
listFlag (false);
string inputName, outputName, archiveDownloadURL;
string inputName, outputName;
bfs::path extractDir (bfs::temp_directory_path ());
SizeArg minAttachSize ("48 Ki");
@ -125,7 +125,6 @@ main (int argc, char** argv) {
("size,s", value<SizeArg> (&minAttachSize)->default_value (minAttachSize), "minimum size for extration")
("updateList,u", bool_switch (&updateListFlag), "list URL need refresh")
("extractDir,d", value<bfs::path> (&extractDir)->default_value (extractDir), "set tmp directory name for extraction")
("archiveDownloadURL,a", value<string> (&archiveDownloadURL)->default_value (archiveDownloadURL), "set url root web site to get bundle (like https://file.kaz.bzh/t.php?)")
;
hide.add_options ()
@ -203,7 +202,7 @@ main (int argc, char** argv) {
cerr << attachment;
if (updateListFlag) {
// update
// case update
mbox.open (inputName);
attachment.getUpdatedURL (mbox);
showTime ("Find old links");
@ -211,7 +210,7 @@ main (int argc, char** argv) {
}
if (outputName.empty ()) {
// extract
// case extract
attachment.setExtractDir (extractDir);
mbox.open (inputName);
attachment.extract (mbox, minAttachSize);
@ -219,9 +218,7 @@ main (int argc, char** argv) {
return 0;
}
// substitute
if (archiveDownloadURL.length ())
attachment.setArchiveDownloadURL (archiveDownloadURL);
// case substitute
mbox.open (inputName);
ofstream outbox (outputName);
attachment.substitute (mbox, outbox, minAttachSize);