Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var system = require('system');
- // antigate
- phantom.injectJs(system.env['HOME'] + '/mailer/vendor/antigatejs/antigate.js');
- var LogicController = function () {
- this.abortUrl = function (url) {
- return false
- || /^http(s)?:\/\/([^\/]+\.)?(c|top-fwz1|rs|ad|webagent|love|filin|r3|portal|reklama|bs)\.mail\.ru/.test(url)
- || /^http(s)?:\/\/([^\/]+\.)?(radar|gstat)\.imgsmail\.ru/.test(url)
- || /^http(s)?:\/\/([^\/]+\.)?(mail|imgsmail)\.ru/.test(url) == false
- }
- this.login = function (input) {
- Casper.open('https://e.mail.ru/messages/inbox/');
- function check_login() {
- Casper.waitFor(
- function check() {
- return this.evaluate(function () {
- return 0
- || $('#LoginExternal').is(':visible') // cookies are empty or outdated
- || $('h1.password-recovery__remind-new-header').is(':visible') // account banned
- || $('a[data-name=compose]:first-child').is(':visible') // ok
- });
- },
- function () {
- if (Casper.visible('#LoginExternal')) {
- Casper.fill('#LoginExternal', {
- 'Login': input.login,
- 'Password': input.password
- }, true);
- Casper.waitFor(
- function () {
- return this.evaluate(function () {
- return !$('#LoginExternal').is(':visible')
- })
- },
- check_login,
- stepTimeout,
- 10000
- )
- }
- else if (Casper.visible('a[data-name=compose]:first-child'))
- Controller.operation_result = true
- else
- Controller.operation_result = Casper.getHTML('h1.password-recovery__remind-new-header').trim()
- },
- stepTimeout,
- 10000
- )
- }
- check_login()
- }
- this.send = function (input) {
- Casper.then(function () {
- Casper.click('a[data-name=compose]:first-child')
- });
- Casper.waitFor(
- function check() {
- return this.evaluate(function () {
- /*
- console.log(''
- + '=' + (typeof tinyMCE !== 'undefined')
- + '=' + (typeof tinyMCE.get(0) !== 'undefined')
- + '=' + tinyMCE.get(0).getContent().indexOf("<br />--")>=0
- + '=' + tinyMCE.get(0).getContent().indexOf("js-signature")<0
- );
- */
- return 1
- && typeof tinyMCE !== 'undefined'
- && typeof tinyMCE.get(0) !== 'undefined'
- && tinyMCE.get(0).getContent().indexOf("<br />--") >= 0
- && tinyMCE.get(0).getContent().indexOf("js-signature") < 0;
- });
- },
- function () {
- //mouse.move('textarea[data-original-name=To]')
- //mouse.click('textarea[data-original-name=To]')
- Casper.sendKeys('textarea[data-original-name=To]', input.to);
- Casper.sendKeys('input[name=Subject]', input.subject);
- Casper.evaluate(function (text) {
- tinyMCE.get(0).setContent(text);
- }, input.text)
- Casper.click('div[data-name=send]')
- },
- stepTimeout,
- 20000
- );
- Casper.waitFor(
- function check() {
- return this.evaluate(function () {
- return 0
- || $('.notify-message__title__text_error').is(':visible')
- || $('.message-sent__title').is(':visible')
- || $('#MailRuConfirm').is(':visible')
- });
- },
- function check_message_status() {
- if (Casper.visible('#MailRuConfirm')) {
- Controller.operation_result = null
- }
- else if (Casper.visible('.message-sent__title'))
- Controller.operation_result = true
- else {
- Controller.operation_result = Casper.evaluate(function () {
- var text = $('.notify-message__title__text_error:visible').html().trim()
- $('.notify').hide();
- return text;
- })
- }
- },
- stepTimeout,
- 40000
- )
- }
- // send with captcha solving - bad idea
- this.send2 = function (input) {
- Casper.then(function () {
- Casper.click('a[data-name=compose]:first-child')
- });
- Casper.waitFor(
- function check() {
- return this.evaluate(function () {
- /*
- console.log(''
- + '=' + (typeof tinyMCE !== 'undefined')
- + '=' + (typeof tinyMCE.get(0) !== 'undefined')
- + '=' + tinyMCE.get(0).getContent().indexOf("<br />--")>=0
- + '=' + tinyMCE.get(0).getContent().indexOf("js-signature")<0
- );
- */
- return 1
- && typeof tinyMCE !== 'undefined'
- && typeof tinyMCE.get(0) !== 'undefined'
- && tinyMCE.get(0).getContent().indexOf("<br />--") >= 0
- && tinyMCE.get(0).getContent().indexOf("js-signature") < 0;
- });
- },
- function () {
- //mouse.move('textarea[data-original-name=To]')
- //mouse.click('textarea[data-original-name=To]')
- Casper.sendKeys('textarea[data-original-name=To]', input.to);
- Casper.sendKeys('input[name=Subject]', input.subject);
- Casper.evaluate(function (text) {
- tinyMCE.get(0).setContent(text);
- }, input.text)
- Casper.click('div[data-name=send]')
- },
- stepTimeout,
- 20000
- );
- var tries = 0;
- function checksend() {
- if (tries >= 3) {
- Controller.operation_result = null
- return;
- }
- tries += 1;
- Casper.waitFor(
- function check() {
- return this.evaluate(function () {
- return 0
- || $('.notify-message__title__text_error').is(':visible')
- || $('.message-sent__title').is(':visible')
- || $('#MailRuConfirm').is(':visible')
- });
- },
- function check_message_status() {
- if (Casper.visible('#MailRuConfirm')) {
- //Controller.operation_result = null
- Casper.evaluate(function () {
- $('#MailRuConfirm > .popup > div:visible .js-captcha-link').click()
- })
- function captcha_load() {
- Casper.waitFor(
- function check_captcha_loaded() {
- return this.evaluate(function () {
- return $('#MailRuConfirm > .popup > div:visible .js-captcha-block img').get(0).complete
- });
- },
- function captcha_loaded() {
- var captcha_src = Casper.evaluate(function () {
- return $('#MailRuConfirm > .popup > div:visible .js-captcha-block img').attr('src')
- });
- if (debug != "true" && debug != "false" && debug)
- Casper.capture(debug + '_' + (new Date()).getTime() + '_captcha.png');
- var captcha_fname = '/tmp/mailru_captcha_' + Math.random() + ".jpg";
- Casper.captureSelector(captcha_fname, '.js-captcha-block img[src="' + captcha_src + '"]');
- //Casper.download(captcha_src, captcha_fname);
- var ag = new AntiGate(
- 'dcdfc8921d3e7ebac57d26c486bdbf16',
- '/root/mailer/vendor/antigatejs/solve_captcha.php'
- );
- ag.send(
- captcha_fname,
- function (text) {
- console.log('captcha=' + text)
- Casper.evaluate(function (code) {
- $('#MailRuConfirm > .popup > div:visible .js-captcha-block input[name=code]').val(code)
- $('#MailRuConfirm > .popup > div:visible .confirm-ok').click()
- }, text)
- }
- )
- Casper.waitWhileVisible(
- '#MailRuConfirm',
- checksend,
- stepTimeout(),
- 120000
- )
- },
- function check_captcha_timeout() {
- console.log('check_captcha_timeout!');
- Casper.evaluate(function () {
- $('#MailRuConfirm > .popup > div:visible a:contains("Не вижу код")').click()
- })
- captcha_load()
- },
- 10000
- )
- }
- captcha_load()
- }
- else if (Casper.visible('.message-sent__title'))
- Controller.operation_result = true
- else {
- Controller.operation_result = Casper.evaluate(function () {
- var text = $('.notify-message__title__text_error:visible').html().trim()
- $('.notify').hide();
- return text;
- })
- }
- },
- stepTimeout,
- 40000
- )
- }
- checksend()
- }
- this.getmessageslist = function (input) {
- Controller.operation_result = [];
- var url = "https://e.mail.ru/messages/inbox/?back=1";
- if (Casper.getCurrentUrl() != url)
- Casper.open(url)
- var sel = (input.onlynew == "true") ? ".b-datalist__item_unread" : ".b-datalist__item";
- var getmessagespage = function () {
- Casper.waitForSelector('#b-letters', function () {
- // fetch messages
- var messages = Casper.evaluate(function (sel) {
- var m = [];
- $('#b-letters ' + sel).each(function () {
- var a = $(this).find('a[rel=history]');
- m[m.length] = {
- 'id': a.attr('href'),
- 'from': a.attr('title'),
- 'subject': a.attr('data-subject')
- }
- })
- return m;
- }, sel)
- for (var i in messages)
- Controller.operation_result[Controller.operation_result.length] = messages[i];
- // goto next page if any
- var hasnextpage = Casper.evaluate(function (onlynew) {
- if (0
- || $('div[data-name=next]').length == 0
- || (onlynew == "true" && $(".b-datalist__item_unread").length < $(".b-datalist__item").length)
- )
- return false;
- var disabled = $('div[data-name=next]').attr('aria-disabled')
- return typeof disabled === typeof undefined || disabled !== "disabled"
- }, input.onlynew);
- if (hasnextpage) {
- Casper.click('div[data-name=next]')
- Casper.waitForSelectorTextChange('#b-letters', function () {
- getmessagespage()
- }, stepTimeout, 30000)
- }
- }, stepTimeout, 30000);
- };
- getmessagespage();
- }
- this.getmessage = function (input) {
- Casper.open(input.id, function () {
- }, stepTimeout, 30000)
- Casper.waitForSelector('.js-readmsg-msg', function () {
- var text = Casper.evaluate(function () {
- return $('.js-readmsg-msg').html()
- })
- var from = Casper.evaluate(function () {
- return $('.b-letter__head__addrs__from .b-contact-informer-target').attr('data-contact-informer-email')
- })
- Controller.operation_result = {
- 'text': text,
- 'from': from
- }
- }, stepTimeout, 30000)
- }
- this.register = function (input) {
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement