<commit_before>var Message = require('../models/message');

exports.create = function(req, res) {
  new Message({
    senderID: req.body.senderID,
    senderAlias: req.body.senderAlias,
    acceptorID: req.body.acceptorID,
    acceptorAlias: req.body.acceptorAlias,
    subject: req.body.subject,
    content: req.body.content
  }).save(function(err, message) {
    if (err) {
        return res.send(400, err);
    }
    res.send(message);
  });
};

exports.list = function(req, res) {
  Message.find({}, function(err, messages) {
    if (err) {
      res.send(500, err);
    }
    res.send(messages || []);
  });
};

exports.remove = function(req, res) {
  // TODO: That's a security flaw, we should also include checks if that is a mesage of the user!!!
    var delFlag = false;
    var saveFlag = false;


    Message.findOne({_id: req.params.id}, function(err, doc){

        if(doc.senderID == req.user._id){
            if(doc.delFromAcceptor == 'true'){
                delFlag=true;
            }else{
                doc.delFromSender = true;
                saveFlag = true;
            }
        }<commit_msg>is done due to the following check<commit_after>var Message = require('../models/message');

exports.create = function(req, res) {
  new Message({
    senderID: req.body.senderID,
    senderAlias: req.body.senderAlias,
    acceptorID: req.body.acceptorID,
    acceptorAlias: req.body.acceptorAlias,
    subject: req.body.subject,
    content: req.body.content
  }).save(function(err, message) {
    if (err) {
        return res.send(400, err);
    }
    res.send(message);
  });
};

exports.list = function(req, res) {
  Message.find({}, function(err, messages) {
    if (err) {
      res.send(500, err);
    }
    res.send(messages || []);
  });
};

exports.remove = function(req, res) {
    var delFlag = false;
    var saveFlag = false;


    Message.findOne({_id: req.params.id}, function(err, doc){

        if(doc.senderID == req.user._id){
            if(doc.delFromAcceptor == 'true'){
                delFlag=true;
            }else{
                doc.delFromSender = true;
                saveFlag = true;
            }
        }
{'fraction_non_alphanumeric': 0.14794267221451687, 'fraction_numerical': 0.005547850208044383, 'mean_word_length': 2.3190184049079754, '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': '5683781', 'n_tokens_mistral': 716, 'n_tokens_neox': 693, 'n_words': 148}