v2
This commit is contained in:
@ -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 => & => & 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
|
||||
|
Reference in New Issue
Block a user