From 45d34e64f4b65638f3c2ba3ee914568c35e75077 Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Tue, 10 Dec 2013 03:50:54 +0400 Subject: [PATCH] Fix logn RE: subjects --- dev/Common/Utils.js | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/dev/Common/Utils.js b/dev/Common/Utils.js index 7620e3dfa..e7e0b6664 100644 --- a/dev/Common/Utils.js +++ b/dev/Common/Utils.js @@ -426,9 +426,10 @@ Utils.removeSelection = function () /** * @param {string} sPrefix * @param {string} sSubject + * @param {boolean=} bFixLongSubject = true * @return {string} */ -Utils.replySubjectAdd = function (sPrefix, sSubject) +Utils.replySubjectAdd = function (sPrefix, sSubject, bFixLongSubject) { var oMatch = null, @@ -450,9 +451,49 @@ Utils.replySubjectAdd = function (sPrefix, sSubject) sResult = sPrefix + ': ' + sSubject; } - return sResult; + sResult = sResult.replace(/[\s]+/g, ' '); + return (Utils.isUnd(bFixLongSubject) ? true : bFixLongSubject) ? Utils.fixLongSubject(sResult) : sResult; }; +/** + * @param {string} sSubject + * @return {string} + */ +Utils.fixLongSubject = function (sSubject) +{ + var + iCounter = 0, + oMatch = null + ; + + sSubject = Utils.trim(sSubject.replace(/[\s]+/, ' ')); + + do + { + oMatch = /^Re(\[([\d]+)\]|):[\s]{0,3}Re(\[([\d]+)\]|):/ig.exec(sSubject); + window.console.log(sSubject); + window.console.log(oMatch); + if (!oMatch || Utils.isUnd(oMatch[0])) + { + oMatch = null; + } + + if (oMatch) + { + iCounter = 0; + iCounter += Utils.isUnd(oMatch[2]) ? 1 : 0 + Utils.pInt(oMatch[2]); + iCounter += Utils.isUnd(oMatch[4]) ? 1 : 0 + Utils.pInt(oMatch[4]); + + sSubject = sSubject.replace(/^Re(\[[\d]+\]|):[\s]{0,3}Re(\[[\d]+\]|):/gi, 'Re' + (0 < iCounter ? '[' + iCounter + ']' : '') + ':'); + } + + } + while (oMatch); + + sSubject = sSubject.replace(/[\s]+/, ' '); + return sSubject; +} + /** * @param {number} iNum * @param {number} iDec