HEX
Server: Apache
System: Linux b:u:newjapaneti:1 3.10.0-1160.31.1.el7.x86_64 #1 SMP Thu Jun 10 13:32:12 UTC 2021 x86_64
User: newjapaneti (381717)
PHP: 5.6.30
Disabled: apache_get_modules, apache_get_version, apache_reset_timeout, apache_getenv, apache_note, apache_setenv
Upload Files
File: //usr/local/sbin/wrapper-mail
#!/usr/bin/python

import sys, getopt, smtplib, email, email.utils

def log(msg):
	"""Log messages to sendmail.log"""

	logfile = "/tmp/sendmail.log"
	try:
		open(logfile, "a+").write("%s\n" % msg)
	except Exception:
		pass

def main():
	log("Sending")
	rcptto = []
	mailfrom = None
	extract_to = False

	opts, rcptto = getopt.gnu_getopt(sys.argv[1:], "tif:")
	if opts and len(opts) > 0:
		for opt in opts:
			if opt and len(opt) > 1 and opt[0] == "-f":
				mailfrom = opt[1]
			if opt and len(opt) > 0 and opt[0] == "-t":
				extract_to = True

	try:
		msg = email.message_from_file(sys.stdin)
	except Exception as err:
		log("Error formatting message: %s" % err)
		return 1

	try:
		if mailfrom is None:
			mailfrom = msg["from"]

		if len(rcptto) == 0 or extract_to is True and msg["to"] is not None:
			rcptto = rcptto + [x.strip() for x in msg["to"].split(",")]

		if msg["date"] == None:
			msg.add_header("Date", email.utils.formatdate(localtime=True))

		server = smtplib.SMTP(host='127.0.0.1', port=25, timeout=30)
		try:
			server.sendmail(mailfrom, rcptto, msg.as_string())
		finally:
			server.quit()
	except Exception as err:
		log("Error sending message: %s" % err)
		return 2

	return 0

if __name__ == "__main__":
	sys.exit(main())