<commit_before>'use strict';

var fs = require('fs');
var MailParser = require('mailparser').MailParser;
var Attachment = require('../mail/mail').Attachment;

/**
 * Normalises attachment files retrieved from file system or parsed raw email
 *
 * @param {Object} file The file object returned by file system or parsed email
 * @return {Object} A SendGrid Attachment object with the file data
 */
function createAttachment(file) {
  var attachment = new Attachment();

  attachment.setFilename(file.originalname || file.fileName);
  attachment.setType(file.mimetype || file.contentType);
  attachment.setContent(file.content.toString('base64'));

  return attachment;
}

/**
 * Simple class that parses data received from SendGrid Inbound Parse Webhook
 */
function Parse(config, request) {
  this.keys = config.keys;
  this.request = request;
  this.payload = request.body || {};
  this.files = request.files || [];
}

/**
 * Return an object literal of key/values in the payload received from webhook
 * @return {Object} Valid key/values in the webhook payload<commit_msg>Update require to use full path and extension<commit_after>'use strict';

var fs = require('fs');
var MailParser = require('mailparser').MailParser;
var Attachment = require('../mail/mail.js').Attachment;

/**
 * Normalises attachment files retrieved from file system or parsed raw email
 *
 * @param {Object} file The file object returned by file system or parsed email
 * @return {Object} A SendGrid Attachment object with the file data
 */
function createAttachment(file) {
  var attachment = new Attachment();

  attachment.setFilename(file.originalname || file.fileName);
  attachment.setType(file.mimetype || file.contentType);
  attachment.setContent(file.content.toString('base64'));

  return attachment;
}

/**
 * Simple class that parses data received from SendGrid Inbound Parse Webhook
 */
function Parse(config, request) {
  this.keys = config.keys;
  this.request = request;
  this.payload = request.body || {};
  this.files = request.files || [];
}

/**
 * Return an object literal of key/values in the payload received from webhook
 * @return {Object} Valid key/values in the webhook payload
{'fraction_non_alphanumeric': 0.11416781292984869, 'fraction_numerical': 0.0018340210912425492, 'mean_word_length': 4.580562659846548, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4412624', 'n_tokens_mistral': 590, 'n_tokens_neox': 587, 'n_words': 206}