This should be:

if (!connection.transaction.mail_from.user) return next();

The has_null_sender function isn't necessary for this