<commit_before>var Imap = require('imap');
var inspect = require('util').inspect;
var MailParser = require("mailparser").MailParser;
var keys = require('./keys.js');

var imap = new Imap({
  user: keys.IMAP_USER,
  password: keys.IMAP_PASSWORD,
  host: 'imap.gmail.com',
  port: 993,
  tls: true,
  tlsOptions: { rejectUnauthorized: false }
});

function openInbox(cb) {
  imap.openBox('INBOX', true, cb);
}

console.log("###############################################################################################################################################");

imap.once('ready', function() {
  openInbox(function(err, box) {
    if (err) throw err;
    var f = imap.seq.fetch(box.messages.total + ':*', { bodies: ['HEADER.FIELDS (FROM TO SUBJECT)','TEXT'] });

    f.on('message', function(msg, seqno) {
      var buffer = '';

      msg.on('body', function(stream, info) {
        stream.on('data', function(chunk) {
          if(info.which === 'TEXT') {
            buffer += chunk.toString();
          } else {
            buffer = chunk.toString() + buffer;
          }
        });
      });

      msg.on('end', function() {
        parser = new MailParser();
        parser.on("end", function(mail_object) {
          console.log("From:", mail_object.from); //[{address:'<EMAIL>',name:'Sender Name'}]
          console.log("Subject:", mail_object.subject); // Hello world!<commit_msg>Test imap file<commit_after>var Imap = require('imap');
var inspect = require('util').inspect;
var MailParser = require("mailparser").MailParser;
var keys = require('./keys.js');

var imap = new Imap({
  user: keys.IMAP_USER,
  password: keys.IMAP_PASSWORD,
  host: 'imap.gmail.com',
  port: 993,
  tls: true,
  tlsOptions: { rejectUnauthorized: false }
});

function openInbox(cb) {
  imap.openBox('INBOX', true, cb);
}

console.log("###############################################################################################################################################");

imap.once('ready', function() {
  openInbox(function(err, box) {
    if (err) throw err;
    var f = imap.seq.fetch('1:' + box.messages.total, { bodies: ['HEADER.FIELDS (FROM TO SUBJECT)','TEXT'] });

    f.on('message', function(msg, seqno) {
      var buffer = '';

      msg.on('body', function(stream, info) {
        stream.on('data', function(chunk) {
          if(info.which === 'TEXT') {
            buffer += chunk.toString();
          } else {
            buffer = chunk.toString() + buffer;
          }
        });
      });

      msg.on('end', function() {
        parser = new MailParser();
        parser.on("end", function(mail_object) {
          console.log("From:", mail_object.from); //[{address:'<EMAIL>',name:'<NAME>'}]
          console.log("Subject:", mail_object.subject); // Hello world!
{'fraction_non_alphanumeric': 0.2705503931379557, 'fraction_numerical': 0.0025017869907076485, 'mean_word_length': 3.400943396226415, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2072749', 'n_tokens_mistral': 854, 'n_tokens_neox': 831, 'n_words': 169}