<commit_before>/**
 * Mailvelope - secure email with OpenPGP encryption for Webmail
 * Copyright (C) 2014 Mailvelope GmbH
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License version 3
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @fileOverview Implements provider specific content scripts to query
 * recipients and set sender email addresses in the webmail ui.
 */

'use strict';

var mvelo = mvelo || {};

mvelo.providers = {};

/**
 * Initializes the map of provider specific modules.
 */
mvelo.providers.init = function() {
  mvelo.providers.map = new Map();
  mvelo.providers.map.set('mail.google.com', new mvelo.providers.Gmail());
  mvelo.providers.map.set('default', new mvelo.providers.Default());
};

/**
 * Lookup function that return the vendor specific module to a hostname.
 * If a hostname if not supported specifically, the default module will
 * be returned.
 * @param  {String} hostname   The hostname of the webmail interface
 * @return {Object}            An instanciated module
 */
mvelo.providers.get = function(hostname) {
  if (mvelo.providers.map.has(hostname)) {
    return mvelo.providers.map.get(hostname);
  } else {
    return mvelo.providers.map.get('default');
  }
};


//
// Provider specific modules
//


(function(mvelo) {

  mvelo.providers.Gmail = Gmail;
  mvelo.providers.Default = Default;


  //
  // Default module ... generic handling for unsupported providers
  //


  function Default() {}

  /**
   * Parse recipients from the DOM for a generic webmail UI.
   * @return {Array}   The recipient objects in fhe form { email: '<EMAIL>' }
   */
  Default.prototype.getRecipients = function() {
    var recipients = [];

    recipients = recipients.concat(dom.getText($('span').filter(':visible')));
    recipients = recipients.concat(dom.getVal($('input, textarea').filter(':visible')));

    return recipients;
  };

  /**
   * Since there is not way to enter recipients in a generic fashion
   * this function does nothing.
   */
  Default.prototype.setRecipients = function() { /* do nothing */ };


  //
  // Gmail module
  //


  function Gmail() {}

  /**
   * Parse recipients from the Gmail Webmail interface
   * @return {Array}   The recipient objects in fhe form { email: '<EMAIL>' }
   */
  Gmail.prototype.getRecipients = function() {
    return dom.getAttr($('.oL.aDm span[email], .vR span[email]'), 'email');
  };

  /**
   * Set tne recipients in the Gmail Webmail editor.
   */
  Gmail.prototype.setRecipients = function(recipients) {
    recipients = recipients || [];
    // find the relevant elements in the Gmail interface
    var displayDiv = $('.oL.aDm'); // displays recipients when focus not on input
    var tagDiv = $('.vR'); // diplays tags for each recipient when focus on input
    var input = $('.vO'); // the actual email address text input (a textarea)
    displayDiv.empty();
    tagDiv.empty();
    input.empty();
    // enter address text into input
    var text = recipients.map(function(r) { return r.email; }).join(', ');
    input.text(text);
    // display recipients in the displayDiv
    recipients.forEach(function(recipient) {
      var email = recipient.email;
      var span = $('<span/>', {email:email});
      span.text(recipient.name ? (recipient.name + ' (' + email + ')') : email);
      displayDiv.append(span);<commit_msg>Only input recipient in To: field not Cc: and Bcc: as well<commit_after>/**
 * Mailvelope - secure email with OpenPGP encryption for Webmail
 * Copyright (C) 2014 Mailvelope GmbH
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License version 3
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @fileOverview Implements provider specific content scripts to query
 * recipients and set sender email addresses in the webmail ui.
 */

'use strict';

var mvelo = mvelo || {};

mvelo.providers = {};

/**
 * Initializes the map of provider specific modules.
 */
mvelo.providers.init = function() {
  mvelo.providers.map = new Map();
  mvelo.providers.map.set('mail.google.com', new mvelo.providers.Gmail());
  mvelo.providers.map.set('default', new mvelo.providers.Default());
};

/**
 * Lookup function that return the vendor specific module to a hostname.
 * If a hostname if not supported specifically, the default module will
 * be returned.
 * @param  {String} hostname   The hostname of the webmail interface
 * @return {Object}            An instanciated module
 */
mvelo.providers.get = function(hostname) {
  if (mvelo.providers.map.has(hostname)) {
    return mvelo.providers.map.get(hostname);
  } else {
    return mvelo.providers.map.get('default');
  }
};


//
// Provider specific modules
//


(function(mvelo) {

  mvelo.providers.Gmail = Gmail;
  mvelo.providers.Default = Default;


  //
  // Default module ... generic handling for unsupported providers
  //


  function Default() {}

  /**
   * Parse recipients from the DOM for a generic webmail UI.
   * @return {Array}   The recipient objects in fhe form { email: '<EMAIL>' }
   */
  Default.prototype.getRecipients = function() {
    var recipients = [];

    recipients = recipients.concat(dom.getText($('span').filter(':visible')));
    recipients = recipients.concat(dom.getVal($('input, textarea').filter(':visible')));

    return recipients;
  };

  /**
   * Since there is not way to enter recipients in a generic fashion
   * this function does nothing.
   */
  Default.prototype.setRecipients = function() { /* do nothing */ };


  //
  // Gmail module
  //


  function Gmail() {}

  /**
   * Parse recipients from the Gmail Webmail interface
   * @return {Array}   The recipient objects in fhe form { email: '<EMAIL>' }
   */
  Gmail.prototype.getRecipients = function() {
    return dom.getAttr($('.oL.aDm span[email], .vR span[email]'), 'email');
  };

  /**
   * Set tne recipients in the Gmail Webmail editor.
   */
  Gmail.prototype.setRecipients = function(recipients) {
    recipients = recipients || [];
    // find the relevant elements in the Gmail interface
    var displayDiv = $('.oL.aDm'); // displays recipients when focus not on input
    var tagDiv = $('.vR'); // diplays tags for each recipient when focus on input
    var input = $('.vO').first(); // the actual email address text input (a textarea)
    displayDiv.empty();
    tagDiv.empty();
    input.empty();
    // enter address text into input
    var text = recipients.map(function(r) { return r.email; }).join(', ');
    input.text(text);
    // display recipients in the displayDiv
    recipients.forEach(function(recipient) {
      var email = recipient.email;
      var span = $('<span/>', {email:email});
      span.text(recipient.name ? (recipient.name + ' (' + email + ')') : email);
      displayDiv.append(span);
{'fraction_non_alphanumeric': 0.1253731343283582, 'fraction_numerical': 0.0012978585334198572, 'mean_word_length': 3.259812050856827, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5145092', 'n_tokens_mistral': 2315, 'n_tokens_neox': 2210, 'n_words': 764}