/** * Plugin Name: ZyGCMailErrors * Plugin URI: https://gcboost.ru/shop/zygcmailerrors/ * Description: Модуль для сбора и обработки пользователей с ошибками после отправке письма в Getcourse * Version: 1.2 * Author: Evgeniy Nayden * Author URI: https://gcboost.ru/ */ !function(e,t){var n={},o="zy-gc-mail-errors",r=0,i=1,a=0,s={},l=[["user_id","email","mail_error","group_id","group_name"]],d={init:function(t){n=e.extend(!0,{groups:{},errors:{domain:["MX lookup failed","need RCPT command SMTP","This domain is not in use and does not accept mail","Connection refused","without being connected","SMTP connect() failed"],spam:["Failed to connect to server SMTP","has been temporarily rate limited due to IP reputation","_is_blocked","abuse","Failed to connect to server 421","Spam detected","Message considered as spam or virus","rejected Your IP","blacklisted","host rejected","Message rejected","blocked using spamsource.mail.yandex.net","Blocked by spam","550 spam message","rejected because IP","Access denied, banned sending IP","listed in Blacklist","please come back later","Greylisted, try again after some time","Greylisted, try again in 180 seconds","please try later","Try again later","in stop list mail"],overquota:["user is over quota","Mailbox size limit exceeded","Mailbox size exceeded","User is overquota","The email account that you tried to reach is over quota","mailbox quota"],user:["mailbox not found","user does not exist","Mailbox does not exist","No such user","Unknown user","User unknown","Recipient address rejected","email account that you tried to reach does not exist","sorry, no mailbox here by that name","no mailbox by that name is currently available","mailbox unavailable","invalid mailbox","Bad recipient address syntax","Bad address mailbox syntax","No correct recipients","We do not relay without RFC2554 authentication","Mailbox is disabled"],dns:["non-local sender verification failed","Check your DNS configuration","sender domain SPF exact match mandatory for IP","This message was not accepted due to domain"]},debug:!1},t),d.debug("options",t),d.debug("settings",n);let o=window.location.href.match(/\/notifications\/control\/messages\/index\?mailingId=([0-9]+)&status=error/);if(o&&o.length>1&&(r=o[1]),!d.checkAccess())return!1;e("head").append(d.getStyles()),d.addActions()},destroy:function(){return this.each((function(){e(this)}))},debug:function(e="key",t={}){n.debug},checkAccess:function(){let e=!1;return window.userInfo&&window.userInfo.isAdmin&&(e=!0),window.location.href.indexOf(`notifications/control/messages/index?mailingId=${r}&status=error`)>=0&&e},getUrlParam:function(e){let t=window.location.href;return new URL(t).searchParams.get(e)},addActions:function(){let t=`\n \n `;e(".panel-body table.values-table").append(`

Управление:

${t}`),e(`#${o}__button-start`).on("click",(function(){e(`#${o}__button-start`).off("click"),d.startErrorsHandle()}))},formSetUsersGroup:function(e){let t=[];for(const n in e)t.push(``);return`\n
\n \n \n \n \n
\n `},startErrorsHandle:function(){d.debug("startErrorsHandle"),e(`#${o}__button-start`).text("Старт обработки ...");const t=parseInt(e(".panel .panel-body table tbody tr:nth-child(4) td:nth-child(2)").text().trim());i=t>0?Math.ceil(t/30):1;for(let e=1;e<=i;e++)!function(e){setTimeout((function(){d.getErrorsCollection(e)}),5e3*e)}(e);let n=setInterval((function(){a==i&&(d.setUsersGroup(),clearInterval(n))}),1e3)},getErrorsCollection:function(t){d.debug("getErrorsCollection page",t);let n=`${window.location.origin}/pl/notifications/control/messages/index?mailingId=${r}&status=error&page=${t}&per-page=30`;e.ajax({url:n,type:"GET",success:function(n){let r={};e(`#${o}__button-start`).text(`Обработано ${t} из ${i}`),e("
",{html:n}).find(".gc-main-content .standard-page-content form ~ table tbody tr").each((function(){let t={id:e("td:nth-child(3) a",this).data("user-id"),login:e("td:nth-child(3) a",this).text(),error:{text:e("td:nth-child(5) span:nth-child(2) span",this).text().toLowerCase().replace(/[\n\r\t\#\&\;\?]/gm," ")}};e("td:nth-child(3) a",this).remove(),t.email=e("td:nth-child(3)",this).text().replace(/[\n\r\t]/gm,""),r[t.id]=t,s[t.id]=t})),a++}})},checkError:function(e){if(e.error.text.length>0)for(const t in n.errors){let o=n.errors[t];for(let n=0;n=0)return t}}return"default"},setUsersGroup:function(){d.debug("setUserGroup"),e(`#${o}__button-start`).text("Идет добавление в группы...");let t={},r=0,i=0;for(const e in s){let o=s[e],r=d.checkError(o);Object.hasOwnProperty.call(t,r)||(t[r]={}),t[r][e]=o,l.push([e,o.email,o.error.text,n.groups[r].id,n.groups[r].name])}r=Object.keys(t).length;for(const r in t){let a={};a[n.groups.default.id]=n.groups.default.name,a[n.groups[r].id]=n.groups[r].name,e(`#${o}__forms`).empty().append(d.formSetUsersGroup(a)),e(`#${o}__set-users-group`).submit((function(t){return t.preventDefault(),e.post(e(this).attr("action"),e(this).serialize()).always((function(){i++})),!1})),e(`#${o}__set-users-group [name="rule"]`).val(JSON.stringify({type:"idsrule",inverted:0,className:"app::components::logic::rule::IdsRule",params:{value:Object.keys(t[r]).toString(),valueMode:null}})),e(`#${o}__set-users-group`).submit()}let a=setInterval((()=>{r==i&&(e(`#${o}__button-start`).text("Готовится отчет..."),d.downloadResult(),clearInterval(a))}),1e3)},downloadResult:function(){let t="data:text/csv;charset=utf-8,";l.forEach((function(e){let n=e.join(";");t+=n+"\r\n"}));let n=encodeURI(t),r=document.createElement("a");r.setAttribute("href",n);let i=(new Date).toISOString().slice(0,10),a=window.location.hostname.replaceAll(".","_");r.setAttribute("download",`users_errors_${a}_${i}.csv`),document.body.appendChild(r),r.click(),e(`#${o}__button-start`).text("Все готово!")},setAdditionalField:function(){},loadingBlock:function(){e("form .form-content").prepend('\n
\n
\n

Получаем данные

\n \n
\n
\n '),e(".loading-block").hide()},getStyles:function(){return"\n \n "}};e.zygcmailerrors=function(t){return d[t]?d[t].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof t&&t?void e.error("Метод с именем "+t+" не существует для jQuery.zygcmailerrors"):d.init.apply(this,arguments)}}(jQuery); /** */