From 7e536fe229d8c71593559e01cffb68ffe5c071c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Thu, 6 May 2021 14:35:57 +0200 Subject: [PATCH] Fix bug : answer lost attach name --- src/cpp/MainAttachment.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/cpp/MainAttachment.cpp b/src/cpp/MainAttachment.cpp index 43fd742..5117e0f 100644 --- a/src/cpp/MainAttachment.cpp +++ b/src/cpp/MainAttachment.cpp @@ -93,8 +93,8 @@ vector Attachment::stringsToUpdate ({KAZ_PLAIN_START, "\""+CID}); // ================================================================================ -const string MainAttachment::templatePlainAddLink (" - "+TMPL_DOWNLOAD+" "+TMPL_FILENAME+"\n"); -const string MainAttachment::templatePlainAllLink ("\n"+KAZ_PLAIN_DOWLOAD_ALL+"\n * "+TMPL_DOWNLOAD+"\n"); +const string MainAttachment::templatePlainAddLink (" - "+TMPL_DOWNLOAD+" "+TMPL_FILENAME+"\r\n"); +const string MainAttachment::templatePlainAllLink ("\r\n"+KAZ_PLAIN_DOWLOAD_ALL+"\r\n * "+TMPL_DOWNLOAD+"\r\n"); const string MainAttachment::templateHtmlHeader (KAZ_HTML_START+"

"+KAZ_PLAIN_START+"


\n" "
" @@ -207,10 +207,10 @@ MainAttachment::getDisclaim (string &plain, string &html) const { return; } - plain = "\n"+KAZ_PLAIN_START+"\n"+KAZ_PLAIN_HR+"\n"+KAZ_PLAIN_DONT_TOUCH+"\n\n"+KAZ_PLAIN_WARNING+"\n\n"+KAZ_PLAIN_DOWLOAD_ONE+"\n"+plainNewLinks; + plain = "\r\n"+KAZ_PLAIN_START+"\r\n"+KAZ_PLAIN_HR+"\r\n"+KAZ_PLAIN_DONT_TOUCH+"\r\n\r\n"+KAZ_PLAIN_WARNING+"\r\n\r\n"+KAZ_PLAIN_DOWLOAD_ONE+"\r\n"+plainNewLinks; html = templateHtmlHeader+htmlNewLinks; if (previousLinks.size ()) { - plain += KAZ_PLAIN_DOWLOAD_OTHER+"\n"+plainOldLinks; + plain += KAZ_PLAIN_DOWLOAD_OTHER+"\r\n"+plainOldLinks; html += templateHtmlOtherLink+htmlOldLinks; } if (linkCount > 1 && archiveDownloadURL.length ()) { @@ -223,7 +223,7 @@ MainAttachment::getDisclaim (string &plain, string &html) const { html += allLinks; } html += templateHtmlFooter; - plain += "\n\n"+KAZ_WEB_SITE+"\n"+KAZ_PLAIN_HR+"\n"+KAZ_PLAIN_STOP+"\n"; + plain += "\r\n\r\n"+KAZ_WEB_SITE+"\r\n"+KAZ_PLAIN_HR+"\r\n"+KAZ_PLAIN_STOP+"\r\n"; // & => & done LOG ("plain: " << plain); LOG ("html: " << html); @@ -252,16 +252,25 @@ MainAttachment::extractLinks (const string &extractedPlainKAZ) { ++stopPos; const string href (extractedPlainKAZ.substr (startPos, stopPos-startPos)); LOG ("plain href: " << href); + if (extractedPlainKAZ [stopPos] && extractedPlainKAZ [stopPos] != '\n') ++stopPos; startPos = stopPos; // get all href but KAZ_WEB_SITE - // the archive link while be skip by filter.sh + // the archive link will be skip by filter.sh if (href == KAZ_WEB_SITE) continue; - while (extractedPlainKAZ [stopPos] && extractedPlainKAZ [stopPos] != '\n') - ++stopPos; - const string name (extractedPlainKAZ.substr (startPos, stopPos-startPos)); + + string::size_type nextPos = extractedPlainKAZ.find ("http", startPos); + string name (extractedPlainKAZ, startPos, (nextPos == string::npos ? extractedPlainKAZ.length () : nextPos) - startPos); + // skip [> \r\n\t] + nextPos = name.find_first_not_of ("[> \t\r\n]"); + if (nextPos != string::npos) + name.erase (0, nextPos); + // stop before [>\r\n\t] + nextPos = name.find_first_of ("[>\t\r\n]"); + if (nextPos != string::npos) + name.erase (nextPos); LOG ("plain name: " << name); addPrevious (href, name); }