-rp to specify the return path of the sent email which can be used where the bounced mails will be sent. Thanks to kullmanp for adding this feature.
+'''(Mar-17-2016)'''
+
+* In quiet mode (-q), list of one line attachments were still printed on stdout.
+* Windows binary linked with OpenSSl 1.0.2h
+'''(May-17-2016)'''
+
+===1.18===
+* Added -read-timeout flag. Default timeout is 5 seconds. When -starttls flag was used with ssl port 465 at gmail, recv() was blocked for a long time. Fixes #61.
+'''(Jun-20-2015)'''
+
+===1.17b15===
+* Released for testing.
+'''(May-25-2014)'''
+
+* When the mail is sent in interactive mode, add a CRLF after the last header. Fixes #58
+'''(May-24-2014)'''
+
+* Read multi line SMTP response messages. Before if the status code was not what was expected, read was stopped after reading the first line. Sometimes it is useful to see all the lines as the messages could tell what is wrong. Fixes #57
+'''(May-24-2014)'''
+
+* If no encoding type was specified for a one line message, it was NULL and a debug message tried to print it causing a seg fault. Fixes Issue #45.
+'''(Feb-01-2014)'''
+
+* The flag -emdbed-image img1 -embed-image imd2 etc to embed image in HTML.
+'''(Dec-27-2013)'''
+
+* The flag -d is changed to -domain. Added new option -disposition to specify the type of content disposition.
+'''(Dec-22-2013)'''
+
+* -enc flag is changed to -enc-type which is used for encoding type of one line messages. This option can be used with -M or -attach.
+'''(Dec-08-2013)'''
+
+* Major changes on how things work. Now each of one line message can have its own character set, mime type and encoding type. Before there was not way to distinguish the messages. The optiopn -attach option also behaves the same way.
+
+* Fixes Issue 29. A file can be included as body of the mail with the flag -msg-body file. The character set and mime type can be specified with -cs and -mime-type flags but files can not be encoded.
+
+* Fixes Issue 37. A new flags -mime-type "type" can be used to specify the MIME type. Default is text/plain. It can be used with -M or -attach.
+'''(Dec-08-2013)'''
+
+* Fixes Issue 36. Only specify filename with -attach. Specify other MIME * parameters with appropriate flags.
+'''(Dec-07-2013)'''
+
+* Fixes Issue 35. The default encoding type is base64. If no encoding should be used, specify encoding type with -enc-type "none".
+'''(Dec-07-2013)'''
+
+* Fixess Issue 34. Try the current addrinfo in connect(), mistakenly the first one was used. If getaddrinfo() returned multiple results and if connect() to first address failed, the rest of the addresses were not tried. Patch sent by Peter Liu.
+'''(Nov-27-2013)'''
+
+* Fixes Issue 30. Support custom Content-type header and to support Conent-ID. The custom Conent-type can be specified with the option -conent-type and the Conent-ID of the attachment can be specified as fifth value of the -attach option. Thanks to skalogryz for supplying the patch.
+'''(Nov-06-2013)'''.
+
+* Fixes Issue 26. Added options -4 and -6 to force using IPv4 or IPv6 address of the SMTP server.
+'''(Oct-20-2013)'''
+
+=== 1.17b14===
+* Multiline input with -M was completely broken.
+ '''(Oct-20-2013)'''
+
+===1.17b13===
+* Changed Copyright to more flexible BSD from GNU GPL. Added -copyright flag.
+'''(Oct-12-2013)'''
+
+* SMTP authentication was broken if the username and passwords are long enough to create longer than 60 characters base64 encoded string. A newline was added after 60 characters causing authentication to fail.
+Fixes Issue 20. Fixes Issue 22.
+'''(Oct-12-2013)'''
+
+* Support DESTDIR during installation. Fixes Issue 5.
+
+* Don't show SSL info in quiet mode. Fixes Issue 21.
+'''(Oct-12-2013)'''
+
+* New ommand line option -enc for Content-Transfer-Encoding. If your one line text message with -M is non-ascii, you should use -enc base64. Note: non-ascii input from windows cmd does not work at this time,
+ however it works fine in linux and mac.
+'''(Jul-01-2013)'''
+
+===1.17b12===
+* Add \r\n to multiple one line messages specified by -M. Possible Fix for Issue 12.
+
+* Do not show attachments in verbose mode. The option -show_attach will enable it. Fixes Issue 13.
+'''(Jun-16-2013)'''
+
+===1.17b11===
+* mailsend writes "Mail sent successfully" message on stdout in interactive mode even if -quiet flag is used. Fixes Issue 6.
+'''(May-05-2013)'''
+
+===1.17b10===
+* If there are some kind of socket error, print the error message. If a log file is specified with -log, the error will be written there.
+'''(Mar-23-2013)'''
+
+* modified Makefile.in to support make -j. Fixes Issue 4.
+
+* fixed several warnings
+'''(Apr-27-2013)'''
+
+===1.17b9===
+* There was a bug if multiple attachments were specified. The temp file was
+ created only once and was removed. The bug shows up in Windows.
+
+* The flag -l is changed to -list.
+
+* A new flag -log is added for logging status messages to a file. It is very alpha at the moment. User -v to see anything useful. The log messages are time stamped.
+'''(Mar-16-2013)'''
+
+===1.17b8===
+* Print more error messages.
+'''(Mar-06-2013)'''
+
+===1.17b7===
+* Print some error message with errno.
+'''(Mar-06-2013)'''
+
+===1.17b6===
+* MIME temp file was created on current working directory. Now go through some huristics to determine the path.
+'''(Mar-05-2013)'''
+
+===1.17b5===
+* getaddrinfo() was not found in ws2_32 dll in Windows 2000. included Wspiapi.h header in msock library as per Microsoft -M "message line 1" -M message line 2"
+'''(Aug-26-2012)'''
+
+* First cut of debian package.
+
+* After sending SMTP EOM, the status code was not checked. It is possible that the server has rejected the mail due to message too large etc. Thanks to Peter Soppe for reporting it.
+'''(Aug-24-2012)'''
+
+* Do not enforce authentication just because server supports it. Do it only if the user wants it.
+'''(Jun-29-2012)'''
+
+* Added flag -ct for connect timeout with SMTP server. The default default timeout is 5 seconds.
+
+* Exit with 0 if everything went well otherwise exit with 1 in case of error.
+
+* created man page. Added install target to Makefile.
+'''(July-05-2012)'''
+
+===1.16===
+* Added support for SMTP over SSL with -ssl. It is different than STARTTLS in the sense that it is not part of SMTP protocol, the entire connection is encrypted from start to end. Note: No checking is performed on certificate. At this time, smtp.gmail.com does SMTP over SSL on port 465.
+'''(Feb-27-2012)'''
+
+* Cleaned up examples. Examples can be seen with -ex, before at least -exa was needed.
+'''(Feb-27-2012)'''
+
+* Created Makefile.nmake for MS Visual Studio 10.
+'''(Feb-28-2012)'''
+
+===1.15b5===
+* New flag '-name "Your Name"' can be used to add your name in the From header, e.g. -f jdoe@example.com -name "John Doe" will create the From header as: From: John Doe -ex is now -example.
+'''(Mar-18-2007)'''
+
+===1.15b3===
+* Compiled on Windows with openssl 0.9.7l.
+* If addresses are specified in a file with -l, do not ask for To. Addresses int he file not not validated howerver.
+
+===1.15b2===
+* New flag -ex show examples.
+
+* New flag -info to show SMTP server info.
+
+* Few bug fixes
+'''(Feb-18-2007)'''
+
+===1.15a===
+* Added support for AUTH CRAM-MD5, AUTH PLAIN and AUTH LOGIN autentication.
+'''(Feb-17-2007)'''
+
+* Added support for AUTH PLAIN
+'''(Feb-11-2007)'''
+
+* The flag "-a" is changed to "-attach"
+'''(Feb-11-2007)'''
+
+* The flags "-m" is gone. There is no need for it anymore, as attachment type can be changed with i or a with the flag -a. If you want a "body" text, specify it with -a "file.txt,text/plain,i" as the first attachment.
+'''(Feb-11-2007)'''
+
+* STARTTLS support. If the SMTP server supports it, enable it in mailsend with flag "-starttls".
+'''(Feb-11-2007)'''
+
+===1.14===
+* Content-disposition can be changed to attachment or inline. Example: -a * "file.gif,image/gif,i". The default is attachment. -a * "file.gif,image.gif,a" is same as a "file.gif,image/gif"
+'''(Feb-06-2007)'''
+
+* Bcc was broken
+'''(Nov-03-2006)'''
+
+===1.13===
+* If no subject is specified with -sub, it'll be empty. Before the default subject was "hello!"
+'''(Jun-25-2006)'''
+
+* The flag -M was broken. Thanks to Amnon S for reporting it.
+'''(Jun-25-2006)'''
+
+* For text attachments, Content-Disposition was always inline. Now it'll be attachment. Thanks to Danny Casier.
+'''(May-21-2006)'''
+
+===1.12===
+* mailsend was not adding Date header. Some SMTP servers does not add it either. Now by default it'll add the Date header (make sure your clock is set properly). If you don't want mailsend to add Date header, use the flag +D. Thanks to Mr S J Hannan for the bug report.
+'''(May-20-2006)'''
+
+===1.11===
+* Attachment seperator character is changed to a , from :. Because in Windows drive is specified with :. Thanks to Jeppe Teglgaard Mohr for pointing it out. Example: -a "c:\file.gif,image/gif"
+'''(Apr-23-2006)'''
+
+* The flag -m is back. This option can be used to attach a text or html file as a blody (inline). Example: -m "file.html,text/html". It is the caller's responsibily to make sure file type is correct. mailsend will not verify if the file is binary or text.
+'''(Apr-23-2006)'''
+
+* New flag -rrr to request read receipts. Suggested by marc hubaut.
+'''(May-14-2006)'''
+
+* New flag -rt to add Reply-To header.
+'''(May-14-2006)'''
+
+===1.10===
+* If the attachment type was text/plain, -msg-body file. It also has a feature to embed images inside HTML which is supported by most mail readers including Outlook. There are some scripts for testing embedding images in HTML in the [[../test|test/]] directory.
+
+== How to find out the capabilities of a SMTP server? ==
+Type any of:
+
+'''c:\> mailsend.exe -info -smtp localhost'''
+
+ [S] 220 t105 ESMTP Exim 4.76 Sun, 04 Mar 2012 14:13:24 -0500
+ [C] EHLO localhost
+ [S] 250-t105 Hello localhost [127.0.0.1]
+ [S] 250-SIZE 52428800
+ [S] 250-PIPELINING
+ [S] 250 HELP
+ [C] QUIT
+ [S] 221 t105 closing connection
+
+'''c:\> mailsend.exe -info -port 587 -smtp smtp.gmail.com'''
+
+ smtp.gmail.com
+ SMTP server: smtp.gmail.com, Port: 587
+ [S] 220 mx.google.com ESMTP xxxxxxxxxxxxxxxx.8
+ [C] EHLO localhost
+ [S] 250-mx.google.com at your service, [x.x.x.x]
+ [S] 250-SIZE 35882577
+ [S] 250-8BITMIME
+ [S] 250-STARTTLS
+ [S] 250 ENHANCEDSTATUSCODES
+ [C] STARTTLS
+ [S] 220 2.0.0 Ready to start TLS
+ Cipher: ECDHE-RSA-RC4-SHA
+ Certificate information:
+ Subject: /C==US/ST==California/L==Mountain View/O==Google Inc/CN==smtp.gmail.com
+ Issuer: /C==US/O==Google Inc/CN==Google Internet Authority
+ [C] EHLO localhost
+ [S] 250-mx.google.com at your service, [x.x.x.x]
+ [S] 250-SIZE 35882577
+ [S] 250-8BITMIME
+ [S] 250-AUTH LOGIN PLAIN XOAUTH
+ [S] 250 ENHANCEDSTATUSCODES
+ [C] QUIT
+ [S] 221 2.0.0 closing connection xxxxxxxxxxxxxxxx.8
+
+'''c:\> mailsend.exe -info -port 465 -ssl -smtp smtp.gmail.com'''
+
+ smtp smtp.gmail.com
+ SMTP server: smtp.gmail.com, Port: 465
+ Cipher: ECDHE-RSA-RC4-SHA
+ Certificate information:
+ Subject: /C==US/ST==California/L==Mountain View/O==Google Inc/CN==smtp.gmail.com
+ Issuer: /C==US/O==Google Inc/CN==Google Internet Authority
+ [S] 220 mx.google.com ESMTP xxxxxxxxxxxxxxxx.19
+ [C] EHLO localhost
+ [S] 250-mx.google.com at your service, [xxx.xxx.xxx.xxx]
+ [S] 250-SIZE 35882577
+ [S] 250-8BITMIME
+ [S] 250-AUTH LOGIN PLAIN XOAUTH
+ [S] 250 ENHANCEDSTATUSCODES
+ [C] QUIT
+ [S] 221 2.0.0 closing connection xxxxxxxxxxxxxxxx.19
+
+== How to embed images in HTML? ==
+mailsend v1.17b15+ has has a feature to embed images inside HTML which is supported by most mail readers including Outlook. This feature can be used to embed one complicated messsage body of the mail. Note: -msg-body file.txt can embed only one text file as message body.
+
+Two screenshots of embedded image in HTML file are shown below:
+
+The HTML file [[../test/embed_image1.html]] is used to send this mail.
+
+[[/images/embed1.png]]
+
+The HTML file [[../test/embed_image2.html]] is used to send this mail.
+
+[[/images/embed2.png]]
+
+To embed images in HTML one below another (without HTML file), mailsend can be run as below:
+
+ $ mailsend -sub "Embed 2 images in HTML, one below the other" \
+ -from mailsend@gmail.com -to mailsend@gmail.com \
+ -smtp smtp.gmail.com -port 587 -starttls -auth \
+ -user mailsend.test@gmail.com -cs ISO-8859-1 \
+ -embed-image "test/blue.png" \
+ -embed-image "test/green.png"
+
+Note: No content ids are specified, they will be generated. The mail will like:
+
+[[/images/embed3.png]]
+
+If you look at the mail at gmail (select Show original), it will look like:
+
+ Subject: Embed 2 images in HTML, one below the other
+ From: mailsend.test@gmail.com
+ Date: Sun, 05 Oct 2014 15:18:10 -0400
+ To: mailsend@gmail.com
+ X-Mailer: @(#) mailsend v1.17b15 (Unix)
+ X-Copyright: BSD. It is illegal to use this software for Spamming
+ Mime-version: 1.0
+ Content-type: multipart/related; boundary="NxSfacGEuTT0nqf7"
+
+ --NxSfacGEuTT0nqf7
+ Content-Type: multipart/alternative; boundary=Stw5amS+Ppc1NmFl
+
+ --Stw5amS+Ppc1NmFl
+ Content-Type: text/html; charset=ISO-8859-1
+
+ mailsend -show-mime-types. In older versions, look at the file [[../mime.types|mime.types]]
diff --git a/coregrade/src/mailsend/doc/mailsend.1 b/coregrade/src/mailsend/doc/mailsend.1
new file mode 100644
index 0000000..f203b5a
--- /dev/null
+++ b/coregrade/src/mailsend/doc/mailsend.1
@@ -0,0 +1,359 @@
+.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
+.\"
+.\" Standard preamble:
+.\" ========================================================================
+.de Sp \" Vertical space (when we can't use .PP)
+.if t .sp .5v
+.if n .sp
+..
+.de Vb \" Begin verbatim text
+.ft CW
+.nf
+.ne \\$1
+..
+.de Ve \" End verbatim text
+.ft R
+.fi
+..
+.\" Set up some character translations and predefined strings. \*(-- will
+.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
+.\" double quote, and \*(R" will give a right double quote. \*(C+ will
+.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
+.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
+.\" nothing in troff, for use with C<>.
+.tr \(*W-
+.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
+.ie n \{\
+. ds -- \(*W-
+. ds PI pi
+. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
+. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
+. ds L" ""
+. ds R" ""
+. ds C` ""
+. ds C' ""
+'br\}
+.el\{\
+. ds -- \|\(em\|
+. ds PI \(*p
+. ds L" ``
+. ds R" ''
+. ds C`
+. ds C'
+'br\}
+.\"
+.\" Escape single quotes in literal strings from groff's Unicode transform.
+.ie \n(.g .ds Aq \(aq
+.el .ds Aq '
+.\"
+.\" If the F register is turned on, we'll generate index entries on stderr for
+.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
+.\" entries marked with X<> in POD. Of course, you'll have to process the
+.\" output yourself in some meaningful fashion.
+.\"
+.\" Avoid warning from groff about undefined register 'F'.
+.de IX
+..
+.nr rF 0
+.if \n(.g .if rF .nr rF 1
+.if (\n(rF:(\n(.g==0)) \{
+. if \nF \{
+. de IX
+. tm Index:\\$1\t\\n%\t"\\$2"
+..
+. if !\nF==2 \{
+. nr % 0
+. nr F 2
+. \}
+. \}
+.\}
+.rr rF
+.\"
+.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
+.\" Fear. Run. Save yourself. No user-serviceable parts.
+. \" fudge factors for nroff and troff
+.if n \{\
+. ds #H 0
+. ds #V .8m
+. ds #F .3m
+. ds #[ \f1
+. ds #] \fP
+.\}
+.if t \{\
+. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
+. ds #V .6m
+. ds #F 0
+. ds #[ \&
+. ds #] \&
+.\}
+. \" simple accents for nroff and troff
+.if n \{\
+. ds ' \&
+. ds ` \&
+. ds ^ \&
+. ds , \&
+. ds ~ ~
+. ds /
+.\}
+.if t \{\
+. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
+. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
+. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
+. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
+. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
+. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
+.\}
+. \" troff and (daisy-wheel) nroff accents
+.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
+.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
+.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
+.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
+.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
+.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
+.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
+.ds ae a\h'-(\w'a'u*4/10)'e
+.ds Ae A\h'-(\w'A'u*4/10)'E
+. \" corrections for vroff
+.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
+.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
+. \" for low resolution devices (crt and lpr)
+.if \n(.H>23 .if \n(.V>19 \
+\{\
+. ds : e
+. ds 8 ss
+. ds o a
+. ds d- d\h'-1'\(ga
+. ds D- D\h'-1'\(hy
+. ds th \o'bp'
+. ds Th \o'LP'
+. ds ae ae
+. ds Ae AE
+.\}
+.rm #[ #] #H #V #F C
+.\" ========================================================================
+.\"
+.IX Title "MAILSEND 1"
+.TH MAILSEND 1 "2019-01-10" "mailsend 1.20b2" "User Commands"
+.\" For nroff, turn off justification. Always turn off hyphenation; it makes
+.\" way too many mistakes in technical documents.
+.if n .ad l
+.nh
+.SH "NAME"
+mailsend \- A command line program to send mail via SMTP protocol
+.SH "SYNOPSYS"
+.IX Header "SYNOPSYS"
+.Vb 1
+\& Version: @(#) mailsend v1.20b2
+\&
+\& Copyright: BSD. It is illegal to use this software for Spamming
+\&
+\& (Compiled with OpenSSL version: OpenSSL 1.0.2q 20 Nov 2018)
+\& usage: mailsend [options]
+\& Where the options are:
+\& \-copyright \- show copyright information
+\& \-4 \- Force to use IPv4 address of SMTP server
+\& \-6 \- Force to use IPv6 address of SMTP server
+\& \-smtp hostname/IP* \- Hostname/IP address of the SMTP server
+\& \-port SMTP port \- SMTP port
+\& \-domain domain \- domain name for SMTP HELO/EHLO
+\& \-t to,to..* \- email address/es of the recipient/s
+\& \-cc cc,cc.. \- carbon copy address/es
+\& +cc \- do not ask for Carbon Copy
+\& \-ct seconds \- Connect timeout. Default is 5 seconds
+\& \-read\-timeout seconds \- Read timeout. Default is 5 seconds
+\& \-bc bcc,bcc.. \- blind carbon copy address/es
+\& +bc \- do not ask for Blind carbon copy
+\& +D \- do not add Date header
+\& \-f address* \- email address of the sender
+\& \-sub subject \- subject
+\& \-list_address file \- a file containing a list of email addresses
+\& \-log file \- write log messages to this file
+\& \-cs character set \- for text/plain attachments (default is us\-ascii)
+\& \-separator character \- separator used with \-attach. Default is comma (,)
+\& If used must be specified before \-attach
+\& \-enc\-type type \- encoding type. base64, 8bit, 7bit etc.
+\& Default is base64. Special type is "none"
+\& \-aname name \- name of the attachment. Default is filename
+\& \-content\-id id \- content\-id in the attachment
+\& \-mime\-type type \- MIME type
+\& \-dispostion val \- "attachment" or "inline". Default is "attachment"
+\& \-attach file,mime_type,[i/a] (i=inline,a=attachment)
+\& \- attach this file as attachment or inline
+\& \-show\-attach \- show attachment in verbose mode, default is no
+\& \-show\-mime\-types \- show the compiled in MIME types
+\& \-M "one line msg" \- attach this one line text message
+\& \-content\-type type \- Content type. Default: multipart/mixed
+\& \-msg\-body path \- Path of the file to include as body of mail
+\& \-embed\-image image \- Path of image to embed in HTML
+\& \-H "header" \- Add custom Header
+\& \-name "Full Name" \- add name in the From header
+\& \-v \- verbose mode
+\& \-V \- show version info
+\& \-w \- wait for a CR after sending the mail
+\& \-rt email_address \- add Reply\-To header
+\& \-rrr email_address \- request read receipts to this address
+\& \-rp \- return\-path address
+\& \-ssl \- SMTP over SSL
+\& \-starttls \- use STARTTLS if the server supports it
+\& \-auth \- try CRAM\-MD5,LOGIN,PLAIN in that order
+\& \-auth\-cram\-md5 \- use AUTH CRAM\-MD5 authentication
+\& \-auth\-plain \- use AUTH PLAIN authentication
+\& \-auth\-login \- use AUTH LOGIN authentication
+\& \-user username \- username for ESMTP authentication
+\& \-pass password \- password for ESMTP authentication
+\& \-example \- show examples
+\& \-ehlo \- force EHLO
+\& \-info \- show SMTP server information
+\& \-help \- shows this help
+\& \-q \- quiet
+\&
+\& The options with * must be specified
+\& Environment variables:
+\& SMTP_USER_PASS for plain text password (\-pass)
+.Ve
+.SH "DESCRIPTION"
+.IX Header "DESCRIPTION"
+mailsend is a simple command line program to send mail via \s-1SMTP\s0 protocol
+for Windows, Linux/Unix.
+.PP
+For deatils, please look at the web page:
+.PP
++ <img src="cid:xx_deadbeefcafe" alt="inline imge"> ++
+
+
+The real HTML file is test/embed_image1.html, available with the source distribution. +
+Notice: only content id is specified with cid, no path of image is specified. +
+ While sending mail with mailsend, we will specify the content id + xx_deadbeefcafe with flag -content-id for the image. +
+Example: +
+Note: Requires mailsend v1.17b15+. The following command was used to +send this mail: +
+ mailsend -v -sub "Testing embedding image in HTML" + -from example@gmail.com -to example@gmail.com + -smtp smtp.gmail.com -port 587 -starttls -auth + -user mailsend.test@gmail.com + -cs ISO-8859-1 + -content-type "multipart/related" + -mime-type text/html + -disposition inline + -enc-type "none" + -attach "test/embedded_image1.html" + -mime-type image/png + -enc-type "base64" + -disposition inline + -content-id "xx_deadbeefcafe" + -cs "none" + -attach "test/blue.png" ++
+
+ Any mail reader that understands multipart-related Content-type will + display the html and the image together. Without the content id, the HTML + and the image will show up as 2 separate attachments. +
+ Tested with gmail, outlook and yahoo mail which can display HTML + file with embedded image. + + diff --git a/coregrade/src/mailsend/test/embed_image2.html b/coregrade/src/mailsend/test/embed_image2.html new file mode 100644 index 0000000..73d3f0c --- /dev/null +++ b/coregrade/src/mailsend/test/embed_image2.html @@ -0,0 +1,69 @@ + +
+
+
+<table border="1"> + <tr> + <td> <img src="cid:img1_deadbeefcafe" alt="inline image 1"></td> + <td> <img src="cid:img2_deadbeefcafe" alt="inline image 2"></td> + </tr> +</table> ++Notice: For the img tag, only the content id is specified with cid but no +path of the image is specified. +
+
+
| |
+ |
+
+
+
+ While sending mail with mailsend, we will specify the content ids + ith flag -content-id for the specfic image. +
+Example: +
+Note: Requires mailsend v1.17b15+. The following command is used to send this mail: +
+ mailsend -v -sub "Testing embedding image in HTML" + -from example@gmail.com -to example@gmail.com + -smtp smtp.gmail.com -port 587 -starttls -auth + -user mailsend.test@gmail.com + -cs ISO-8859-1 + -content-type "multipart/related" + -mime-type text/html + -disposition inline + -enc-type "none" + -attach "test/embedded_image2.html" + -mime-type image/png + -enc-type "base64" + -disposition inline + -content-id "img1_deadbeefcafe" + -cs "none" + -attach "test/blue.png" + -content-id "img2_deadbeefcafe" + -cs "none" + -attach "test/green.png" ++
+ Any mail reader that understands multipart-related Content-type will + display the html and the image together. Without the content id, the HTML + and the image will show up as 2 separate attachments. +
+ Tested with gmail, outlook and yahoo mail which can display HTML
+ file with embedded image.
+
+
diff --git a/coregrade/src/mailsend/test/green.png b/coregrade/src/mailsend/test/green.png
new file mode 100644
index 0000000..19dd7d4
Binary files /dev/null and b/coregrade/src/mailsend/test/green.png differ
diff --git a/coregrade/src/mailsend/test/red.png b/coregrade/src/mailsend/test/red.png
new file mode 100644
index 0000000..b302117
Binary files /dev/null and b/coregrade/src/mailsend/test/red.png differ
diff --git a/coregrade/src/mailsend/test/test.gif b/coregrade/src/mailsend/test/test.gif
new file mode 100644
index 0000000..c166ab7
Binary files /dev/null and b/coregrade/src/mailsend/test/test.gif differ
diff --git a/coregrade/src/mailsend/test/test.png b/coregrade/src/mailsend/test/test.png
new file mode 100644
index 0000000..803790c
Binary files /dev/null and b/coregrade/src/mailsend/test/test.png differ
diff --git a/coregrade/src/mailsend/test/test.txt b/coregrade/src/mailsend/test/test.txt
new file mode 100644
index 0000000..ca94d2d
--- /dev/null
+++ b/coregrade/src/mailsend/test/test.txt
@@ -0,0 +1,14 @@
+Mittagspause
+
+WOLF WONDRATSCHEK
+
+Sie sitzt im Straßencafé. Sie schlägt sofort die Beine übereinander. Sie
+hat wenig Zeit. Sie blättert in einem Modejournal. Die Eltern wissen, dass
+sie schön ist. Sie sehen es nicht gern.
+
+Zum Beispiel. Sie hat Freunde. Trotzdem sagt sie nicht, das ist mein
+bester Freund, wenn sie zu Hause einen Freund
+vorstellt.
+
+Zum Beispiel. Die Männer lachen und schauen herüber und stellen sich ihr
+Gesicht ohne Sonnenbrille vor.
diff --git a/coregrade/src/mailsend/test/test_emded1.rb b/coregrade/src/mailsend/test/test_emded1.rb
new file mode 100755
index 0000000..671019d
--- /dev/null
+++ b/coregrade/src/mailsend/test/test_emded1.rb
@@ -0,0 +1,110 @@
+#!/usr/bin/env ruby
+# Muhammad.Muquit@bt.com Dec-24-2013
+class TestEmbeddedImage
+ PROG = Dir.pwd + "/mailsend"
+ ME = File.basename($0)
+ def initialize
+ $stdout.sync = true
+ if !File.exists?(PROG)
+ log "Error: #{PROG} does not exit"
+ exit 0
+ end
+ @pass = nil
+ @to = nil
+ @from = nil
+ end
+
+ def log(msg)
+ puts "#{msg}"
+ end
+
+
+ def check_args
+ if ARGV.length != 2
+ puts <<-EOF
+ Usage: #{ME}
" \
+ -cs "utf-8" \
+ -mime-type "text/plain" \
+ -enc-type "base64" \
+ -M "Ich lerne seit ungefähr zwei Jahren Deutsch" \
+ -cs "iso-8859-1" \
+ -enc-type "8bit" \
+ -mime-type "text/plain" \
+ -content-disposition "inline" \
+ -attach "test/test.txt" \
+ -attach "test/test.gif" \
+ -cs "Big5" \
+ -enc-type "base64" \
+ -mime-type "text/plain" \
+ -M "中文測試"
diff --git a/coregrade/src/mailsend/test/test_gmail3.bat b/coregrade/src/mailsend/test/test_gmail3.bat
new file mode 100644
index 0000000..fd94592
--- /dev/null
+++ b/coregrade/src/mailsend/test/test_gmail3.bat
@@ -0,0 +1 @@
+mailsend.exe -to %1 -from %2 -sub "test from windows" -starttls -port 587 -auth -smtp smtp.gmail.com -user "%2" -pass %SMTP_USER_PASS% -separator "|" -attach "c:\File,with,comma.txt|text/plain" -v
diff --git a/coregrade/src/mailsend/test/test_gmail4.bat b/coregrade/src/mailsend/test/test_gmail4.bat
new file mode 100644
index 0000000..e1febbe
--- /dev/null
+++ b/coregrade/src/mailsend/test/test_gmail4.bat
@@ -0,0 +1 @@
+mailsend.exe -to %1 -from %2 -sub "test from windows" -starttls -port 587 -auth -smtp smtp.gmail.com -user "%2" -pass %SMTP_USER_PASS% -separator "|" -enc-type "base64" -attach "c:\blue,comma space.png|image/png" -v
diff --git a/coregrade/src/mailsend/test/test_gmail_html.sh b/coregrade/src/mailsend/test/test_gmail_html.sh
new file mode 100755
index 0000000..05c9987
--- /dev/null
+++ b/coregrade/src/mailsend/test/test_gmail_html.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+# muquit@muquit.com Jan-21-2013
+#set -x
+ME=`basename $0`
+TO=$TO
+if [ x"$TO" = x ]; then
+ echo "TO environment variable is not not"
+ exit 1
+fi
+FROM=$FROM
+if [ x"$FROM" = x ]; then
+ echo "FROM environment variable is not not"
+ exit 1
+fi
+
+if [ x"$Cc" != x ]; then
+ CC="-cc $Cc"
+fi
+
+if [ x"$bcc" != x ]; then
+ bcc="-bc ${bcc}"
+fi
+echo "BCc: $bcc"
+
+pass=$SMTP_USER_PASS
+if [ x"$pass" = x ]; then
+ echo "SMTP_USER_PASS environment variable is not not"
+ exit 1
+fi
+
+#SMTP=smtp.comcast.net
+SMTP=smtp.gmail.com
+
+BINARY="./mailsend"
+echo "$OS"
+if [ x"$OS" = x"Windows_NT" ]; then
+ BINARY="./mailsend.exe"
+fi
+os=`uname`
+os="foo"
+if [ x"$os" = x"Linux" ]; then
+VALGRIND_LOG=/tmp/valgrind.log
+VALGRIND="valgrind -v --tool=memcheck --leak-check=yes --error-limit=yes --log-file=$VALGRIND_LOG"
+/bin/rm -f $VALGRIND_LOG
+else
+VALGRIND=""
+fi
+set -x
+
+$VALGRIND $BINARY -to $TO ${CC} ${bcc} -from $FROM \
+ -v \
+ -starttls -port 587 -auth \
+ -smtp $SMTP \
+ -sub "Hello" \
+ -mime-type "text/html" \
+ -M "Hello world" \
+-user "$FROM" -pass "$PASS"
diff --git a/coregrade/src/mailsend/test/test_gmail_list.sh b/coregrade/src/mailsend/test/test_gmail_list.sh
new file mode 100755
index 0000000..6fd4ae2
--- /dev/null
+++ b/coregrade/src/mailsend/test/test_gmail_list.sh
@@ -0,0 +1,86 @@
+#!/bin/sh
+
+# muquit@muquit.com Jan-21-2013
+#set -x
+ME=`basename $0`
+ARGC=$#
+if [ $ARGC != 1 ]; then
+ echo "USage: ${ME} "
+ exit 1
+fi
+LIST_FILE=$1
+
+if [ ! -f ${LIST_FILE} ]; then
+ echo "File '${LIST_FILE}' does not exist"
+ exit 1
+fi
+
+TO=$TO
+if [ x"$TO" = x ]; then
+ echo "TO environment variable is not not"
+ exit 1
+fi
+
+
+FROM=$FROM
+if [ x"$FROM" = x ]; then
+ echo "FROM environment variable is not not"
+ exit 1
+fi
+
+pass=$SMTP_USER_PASS
+if [ x"$pass" = x ]; then
+ echo "SMTP_USER_PASS environment variable is not not"
+ exit 1
+fi
+
+#SMTP=smtp.comcast.net
+SMTP=smtp.gmail.com
+
+BINARY="./mailsend"
+echo "$OS"
+if [ x"$OS" = x"Windows_NT" ]; then
+ BINARY="./mailsend.exe"
+fi
+os=`uname`
+os="foo"
+if [ x"$os" = x"Linux" ]; then
+VALGRIND_LOG=/tmp/valgrind.log
+VALGRIND="valgrind -v --tool=memcheck --leak-check=yes --error-limit=yes --log-file=$VALGRIND_LOG"
+/bin/rm -f $VALGRIND_LOG
+else
+VALGRIND=""
+fi
+set -x
+
+$VALGRIND $BINARY -t "${TO}" -list-address ${LIST_FILE} -from $FROM \
+ -v \
+ -starttls -port 587 -auth \
+ -smtp $SMTP \
+ -cs "utf-8" \
+ -H "X-Priority: 1" -H "Importance: high" \
+ -sub "testing mailsend" \
+ -user "$FROM" -pass "$PASS" \
+ -enc-type "none" \
+ -mime-type "text/plain" \
+ -M "one line attachment 1" \
+ -enc-type "none" \
+ -mime-type "text/plain" \
+ -M "one line attachment 2" \
+ -mime-type "text/html" \
+ -enc-type "none" \
+ -M "this is a test
" \
+ -cs "utf-8" \
+ -mime-type "text/plain" \
+ -enc-type "base64" \
+ -M "Ich lerne seit ungefähr zwei Jahren Deutsch" \
+ -cs "iso-8859-1" \
+ -enc-type "8bit" \
+ -mime-type "text/plain" \
+ -content-disposition "inline" \
+ -attach "test/test.txt" \
+ -attach "test/test.gif" \
+ -cs "Big5" \
+ -enc-type "base64" \
+ -mime-type "text/plain" \
+ -M "中文測試"
diff --git a/coregrade/src/mailsend/test/test_gmail_quiet.sh b/coregrade/src/mailsend/test/test_gmail_quiet.sh
new file mode 100755
index 0000000..bd4d85b
--- /dev/null
+++ b/coregrade/src/mailsend/test/test_gmail_quiet.sh
@@ -0,0 +1,72 @@
+#!/bin/sh
+
+# muquit@muquit.com Jan-21-2013
+#set -x
+ME=`basename $0`
+TO=$TO
+if [ x"$TO" = x ]; then
+ echo "TO environment variable is not not"
+ exit 1
+fi
+FROM=$FROM
+if [ x"$FROM" = x ]; then
+ echo "FROM environment variable is not not"
+ exit 1
+fi
+
+pass=$SMTP_USER_PASS
+if [ x"$pass" = x ]; then
+ echo "SMTP_USER_PASS environment variable is not not"
+ exit 1
+fi
+
+#SMTP=smtp.comcast.net
+SMTP=smtp.gmail.com
+
+BINARY="./mailsend"
+echo "$OS"
+if [ x"$OS" = x"Windows_NT" ]; then
+ BINARY="./mailsend.exe"
+fi
+os=`uname`
+os="foo"
+if [ x"$os" = x"Linux" ]; then
+VALGRIND_LOG=/tmp/valgrind.log
+VALGRIND="valgrind -v --tool=memcheck --leak-check=yes --error-limit=yes --log-file=$VALGRIND_LOG"
+/bin/rm -f $VALGRIND_LOG
+else
+VALGRIND=""
+fi
+#set -x
+
+$VALGRIND $BINARY -to $TO -from $FROM \
+ -q \
+ -starttls -port 587 -auth \
+ -smtp $SMTP \
+ -cs "utf-8" \
+ -H "X-Priority: 1" -H "Importance: high" \
+ -sub "testing mailsend" +cc +bc \
+ -user "$FROM" -pass "$PASS" \
+ -enc-type "none" \
+ -mime-type "text/plain" \
+ -M "one line attachment 1" \
+ -enc-type "none" \
+ -mime-type "text/plain" \
+ -M "one line attachment 2" \
+ -mime-type "text/html" \
+ -enc-type "none" \
+ -M "this is a test
" \
+ -cs "utf-8" \
+ -mime-type "text/plain" \
+ -enc-type "base64" \
+ -M "Ich lerne seit ungefähr zwei Jahren Deutsch" \
+ -cs "iso-8859-1" \
+ -enc-type "8bit" \
+ -mime-type "text/plain" \
+ -content-disposition "inline" \
+ -attach "test/test.txt" \
+ -attach "test/test.gif" \
+ -cs "Big5" \
+ -enc-type "base64" \
+ -mime-type "text/plain" \
+ -M "中文測試"
diff --git a/coregrade/src/mailsend/test/test_issue108.sh b/coregrade/src/mailsend/test/test_issue108.sh
new file mode 100755
index 0000000..4001cd3
--- /dev/null
+++ b/coregrade/src/mailsend/test/test_issue108.sh
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+# muquit@muquit.com Jan-21-2013
+#set -x
+ME=`basename $0`
+TO=$TO
+if [ x"$TO" = x ]; then
+ echo "TO environment variable is not not"
+ exit 1
+fi
+FROM=$FROM
+if [ x"$FROM" = x ]; then
+ echo "FROM environment variable is not not"
+ exit 1
+fi
+
+if [ x"$Cc" != x ]; then
+ CC="-cc $Cc"
+fi
+
+if [ x"$bcc" != x ]; then
+ bcc="-bc ${bcc}"
+fi
+echo "BCc: $bcc"
+
+pass=$SMTP_USER_PASS
+if [ x"$pass" = x ]; then
+ echo "SMTP_USER_PASS environment variable is not not"
+ exit 1
+fi
+
+#SMTP=smtp.comcast.net
+SMTP=smtp.gmail.com
+
+BINARY="./mailsend"
+echo "$OS"
+if [ x"$OS" = x"Windows_NT" ]; then
+ BINARY="./mailsend.exe"
+fi
+os=`uname`
+os="foo"
+if [ x"$os" = x"Linux" ]; then
+VALGRIND_LOG=/tmp/valgrind.log
+VALGRIND="valgrind -v --tool=memcheck --leak-check=yes --error-limit=yes --log-file=$VALGRIND_LOG"
+/bin/rm -f $VALGRIND_LOG
+else
+VALGRIND=""
+fi
+set -x
+
+$VALGRIND $BINARY -to $TO ${CC} ${bcc} -from $FROM \
+ -v \
+ -starttls -port 587 -auth \
+ -smtp $SMTP \
+ -cs "utf-8" \
+ -sub "testing issue 108" \
+ -user "$FROM" -pass "$PASS" \
+ -cs "utf-8" \
+ -mime-type "text/plain" \
+ -enc-type "base64" \
+ -content-disposition "inline" \
+ -M "one line attachment base64 encoding" \
+ -mime-type "application/pdf" \
+ -attach "/home/muquit/junk/test.pdf"
diff --git a/coregrade/src/mailsend/test/test_onelines1.sh b/coregrade/src/mailsend/test/test_onelines1.sh
new file mode 100755
index 0000000..eb835b9
--- /dev/null
+++ b/coregrade/src/mailsend/test/test_onelines1.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+# test online messages with -M
+# Issue# 45
+# muquit@muquit.com Feb-01-2014
+TO=$TO
+if [ x"$TO" = x ]; then
+ echo "TO environment variable is not not"
+ exit 1
+fi
+FROM=$FROM
+if [ x"$FROM" = x ]; then
+ echo "FROM environment variable is not not"
+ exit 1
+fi
+
+pass=$SMTP_USER_PASS
+if [ x"$pass" = x ]; then
+ echo "SMTP_USER_PASS environment variable is not not"
+ exit 1
+fi
+
+./mailsend -v -sub "testing oneline messages no encoding type" \
+ -from $FROM -to $TO \
+ -smtp smtp.gmail.com -port 587 -starttls -auth \
+ -user $FROM \
+ -M "Three one line messages including this one" \
+ -M "one line message 1" \
+ -M "one line message 2"
diff --git a/coregrade/src/mailsend/test/test_readtimeout.sh b/coregrade/src/mailsend/test/test_readtimeout.sh
new file mode 100755
index 0000000..b91ff2b
--- /dev/null
+++ b/coregrade/src/mailsend/test/test_readtimeout.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+# test read timeout, use -startls and specify port 465
+# Issue #61
+# muquit@muquit.com Aug-17-2014
+TO=$TO
+if [ x"$TO" = x ]; then
+ echo "TO environment variable is not not"
+ exit 1
+fi
+FROM=$FROM
+if [ x"$FROM" = x ]; then
+ echo "FROM environment variable is not not"
+ exit 1
+fi
+
+pass=$SMTP_USER_PASS
+if [ x"$pass" = x ]; then
+ echo "SMTP_USER_PASS environment variable is not not"
+ exit 1
+fi
+OS=`uname -s`
+if [ x"$OS" = x"MINGW32_NT-6.1" ]; then
+MAILSEND=mailsend.exe
+else
+MAILSEND=./mailsend
+fi
+
+N=3
+echo "mailsend should timeout after $N seconds"
+# It should timeout after N seconds
+$MAILSEND -v -sub "testing read timeout" \
+ -from $FROM -to $TO \
+ -smtp smtp.gmail.com -port 465 -starttls -auth \
+ -user $FROM \
+ -read-timeout $N \
+ -M "This mail will never be sent"
+echo "Exit code: $?"
diff --git a/coregrade/src/mailsend/test/testimage.svg b/coregrade/src/mailsend/test/testimage.svg
new file mode 100644
index 0000000..2795140
--- /dev/null
+++ b/coregrade/src/mailsend/test/testimage.svg
@@ -0,0 +1,114 @@
+
+
+
+
diff --git a/coregrade/src/mailsend/utils.c b/coregrade/src/mailsend/utils.c
old mode 100644
new mode 100755
index 793462b..ae6948f
--- a/coregrade/src/mailsend/utils.c
+++ b/coregrade/src/mailsend/utils.c
@@ -8,10 +8,22 @@
*/
#include "mailsend.h"
+#include "copyright.h"
+
#define DAY_MIN (24 * HOUR_MIN) /* minutes in a day */
#define HOUR_MIN 60 /* minutes in an hour */
#define MIN_SEC 60 /* seconds in a minute */
+static struct _MimeType
+{
+ char
+ *ext,
+ *val;
+} s_mime_type[] =
+{
+#include "mime_types.h"
+};
+
/*
** returns a positive number if the file descriptor is connected to
@@ -42,10 +54,50 @@ int isInteractive(void)
return(0);
}
+
+/*
+** arg: type
+** at this time valid types are: "base64", "none"
+*/
+int get_encoding_type(const char *type)
+{
+ if (type == NULL || *type == '\0')
+ {
+ return ENCODE_BASE64;
+ }
+ if (strncmp("base64", type, 6) == 0)
+ {
+ return ENCODE_BASE64;
+ }
+ else if (strncmp("none", type, 4) == 0)
+ {
+ return ENCODE_NONE;
+ }
+
+ return ENCODE_BASE64;
+}
+
+int get_content_disposition(const char *disposition)
+{
+ if (disposition == NULL || *disposition == '\0')
+ {
+ return CONTENT_DISPOSITION_ATTACHMENT;
+ }
+ if (strncmp("attachment", disposition, 10) == 0)
+ {
+ return CONTENT_DISPOSITION_ATTACHMENT;
+ }
+ else if (strncmp("inline", disposition, 6) == 0)
+ {
+ return CONTENT_DISPOSITION_INLINE;
+ }
+ return CONTENT_DISPOSITION_ATTACHMENT;
+}
+
/*
** duplicate a string. exits on failure
*/
-char *xStrdup (char *string)
+char *xStrdup (const char *string)
{
char
*tmp;
@@ -59,13 +111,34 @@ char *xStrdup (char *string)
if (tmp == (char *) NULL)
{
(void) fprintf(stderr,"Error: mystrdup(): memory allocation problem\n");
- exit(0);
+ exit_error();
}
/* it's safe to copy this way */
(void) strcpy(tmp, string);
return (tmp);
}
+void log_info(const char *fmt, ...)
+{
+ va_list
+ args;
+
+ va_start(args, fmt);
+ va_end(args);
+}
+
+void log_debug(const char *fmt, ...)
+{
+}
+
+void log_error(const char *fmt, ...)
+{
+}
+
+void log_fatal(const char *fmt, ...)
+{
+}
+
void errorMsg(char *format,...)
{
va_list
@@ -75,6 +148,21 @@ void errorMsg(char *format,...)
(void) fprintf (stderr,"Error: ");
vfprintf(stderr,format,args);
(void) fprintf(stderr,"\n");
+ (void) fflush(stderr);
+
+ if (g_log_fp != NULL)
+ {
+ MutilsTime
+ mt;
+ char
+ timebuf[64];
+ mutils_time_now(&mt);
+ mutils_time_fmt(&mt,timebuf,sizeof(timebuf));
+ (void) fprintf (g_log_fp,"%s: Error: ",timebuf);
+ vfprintf(g_log_fp,format,args);
+ (void) fprintf(g_log_fp,"\n");
+ (void) fflush(g_log_fp);
+ }
va_end(args);
}
@@ -82,15 +170,35 @@ void showVerbose(char *format,...)
{
va_list
args;
+
if (g_quiet)
return;
if (g_verbose == 1)
{
- va_start(args,format);
- vfprintf(stdout,format,args);
- (void) fflush(stdout);
- va_end(args);
+ if (isInConsole(_fileno(stdout)))
+ {
+ va_start(args,format);
+ vfprintf(stdout,format,args);
+ (void) fflush(stdout);
+ va_end(args);
+ }
+
+ if (g_log_fp != NULL)
+ {
+ MutilsTime
+ mt;
+ char
+ timebuf[64];
+ mutils_time_now(&mt);
+ mutils_time_fmt(&mt,timebuf,sizeof(timebuf));
+ (void) fprintf(g_log_fp,"%s: " ,timebuf);
+ va_start(args,format);
+ vfprintf(g_log_fp,format,args);
+ (void) fflush(g_log_fp);
+ va_end(args);
+ }
+
}
}
@@ -106,7 +214,50 @@ void print_info(char *format,...)
vfprintf(stdout,format,args);
(void) fflush(stdout);
va_end(args);
+}
+void write_log(char *format,...)
+{
+ va_list
+ args;
+
+ MutilsTime
+ mt;
+ char
+ timebuf[64];
+
+ if (g_log_fp == NULL)
+ return;
+
+ mutils_time_now(&mt);
+ mutils_time_fmt(&mt,timebuf,sizeof(timebuf));
+
+ va_start(args,format);
+ (void) fprintf(g_log_fp,"%s: " ,timebuf);
+ vfprintf(g_log_fp,format,args);
+ (void) fflush(g_log_fp);
+ va_end(args);
+}
+
+void close_log(void)
+{
+ if (g_log_fp != NULL)
+ {
+ (void) fclose(g_log_fp);
+ g_log_fp = NULL;
+ }
+}
+
+void exit_ok(void)
+{
+ close_log();
+ exit(0);
+}
+
+void exit_error(void)
+{
+ close_log();
+ exit(1);
}
@@ -188,6 +339,7 @@ int validateMusts(char *from,char *to,char *smtp_server,char *helo_domain)
char *askFor(char *buf,int buflen,char *label,int ask)
{
+ char *s;
if (label == NULL || *label == '\0')
return (NULL);
@@ -195,13 +347,13 @@ char *askFor(char *buf,int buflen,char *label,int ask)
again:
if (isInConsole(_fileno(stdin)))
{
- (void) fprintf(stdout,label);
+ (void) fprintf(stdout,"%s",label);
(void) fflush(stdout);
(void) fflush(stderr);
}
- (void) fgets(buf,buflen,stdin);
- if (*buf == '\0' || *buf == '\n')
+ s = fgets(buf,buflen,stdin);
+ if (s == NULL || *buf == '\0' || *buf == '\n')
{
if (ask == EMPTY_NOT_OK)
goto again;
@@ -259,11 +411,13 @@ int get_filepath_mimetype(char *str,char *filepath,int fp_size,char *mype_type,i
{
int
+ separator,
rc=0;
char
*fp,
*mt;
- if ((mt=strchr(str,ATTACHMENT_SEP)))
+ separator = *g_attach_sep;
+ if ((mt=strchr(str,separator)))
{
*mt++='\0';
}
@@ -272,11 +426,11 @@ int get_filepath_mimetype(char *str,char *filepath,int fp_size,char *mype_type,i
errorMsg("Could not determine mime-type from input: %s\n",str);
return(-1);
}
- mutilsSafeStrcpy(mype_type,mt,mt_size);
+ mutilsSafeStrcpy(mype_type,mt,mt_size-1);
/* get the filepath out */
fp=str;
- mutilsSafeStrcpy(filepath,fp,fp_size);
+ mutilsSafeStrcpy(filepath,fp,fp_size-1);
return(rc);
}
@@ -289,6 +443,7 @@ void initialize_openssl(char *cipher)
SSL_library_init();
SSL_load_error_strings();
RAND_seed(rnd_seed,sizeof(rnd_seed));
+ OpenSSL_add_all_algorithms();
ssl_ctx=SSL_CTX_new(SSLv23_client_method());
if (ssl_ctx == NULL)
{
@@ -403,11 +558,15 @@ int rfc822_date(time_t when,char *datebuf,int bufsiz)
/*
** return 0 on success, -1 on failure
+** super simple naive funtion to detect if a file is
+** binary or not.. it's just to prevent attaching binary file
+** if no encoding type is specified. It's not a simple task
+** to detect if a file is binary or not correctly.
*/
int guess_file_type(char *file,unsigned int *flag)
{
char
- buf[BUFSIZ];
+ buf[513];
int
i,
@@ -474,6 +633,7 @@ ExitProcessing:
}
+/*
static int unix2dos(FILE *ifp,FILE *ofp)
{
int
@@ -489,7 +649,7 @@ static int unix2dos(FILE *ifp,FILE *ofp)
return(-1);
#ifdef WINNT
_setmode(_fileno(ofp),_O_BINARY);
-#endif /* WINNT */
+#endif
while(!feof(ifp))
{
n=fread(buf,1,BUFSIZ,ifp);
@@ -513,7 +673,82 @@ static int unix2dos(FILE *ifp,FILE *ofp)
}
}
}
+*/
+void print_copyright(void)
+{
+ char
+ **p;
+
+ for (p = mailsend_copyright; *p != NULL; p++)
+ {
+ (void) fprintf(stdout,"%s\n",*p);
+ }
+ (void) fflush(stdout);
+}
+
+/*
+** Return the MIME type of the file
+** Parameters:
+** path - path of the file
+** Return Values:
+** mime type
+** Side Effects:
+** none
+** Comments:
+** If no extension is found, "text/plain" will be returned
+** Development History:
+*/
+char *get_mime_type(char *path)
+{
+ char
+ *npath = NULL,
+ *ext = NULL;
+
+ char
+ *text_plain = "text/plain";
+ int
+ i;
+
+ if (path == NULL || *path == '\0')
+ {
+ return(text_plain);
+ }
+
+ /* Issue #140. path was modified */
+ npath = xStrdup(path);
+ ext = mutilsExtensionLower(npath);
+ for (i=0; i < sizeof(s_mime_type)/sizeof(*s_mime_type); i++)
+ {
+ if (strcmp(s_mime_type[i].ext, ext) == 0)
+ {
+ if (npath != NULL)
+ {
+ (void) free((char *) npath);
+ }
+ return (s_mime_type[i].val);
+ }
+ }
+ if (npath != NULL)
+ {
+ (void) free((char *) npath);
+ }
+
+ return(text_plain);
+}
+
+void show_mime_types()
+{
+ int
+ i;
+ for (i=0; i < sizeof(s_mime_type)/sizeof(*s_mime_type); i++)
+ {
+ (void) fprintf(stdout,"%s\t%s\n",
+ s_mime_type[i].val,
+ s_mime_type[i].ext);
+ }
+
+}
#ifdef HAVE_OPENSSL
void print_cert_info(SSL *ssl)
@@ -576,8 +811,19 @@ char *encode_cram_md5(char *challenge,char *user,char *secret)
unsigned char
hmac_md5[16];
+#ifdef LIBRESSL_VERSION_NUMBER
HMAC_CTX
ctx;
+#else
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+ HMAC_CTX
+ ctx;
+#else
+ /* OpenSSL 1.1.x*/
+ HMAC_CTX
+ *ctx;
+#endif
+#endif
const EVP_MD
*md5=NULL;
@@ -591,9 +837,10 @@ char *encode_cram_md5(char *challenge,char *user,char *secret)
char
*b64;
+ /*
unsigned long
b64len=0;
-
+ */
char
hex[33],
buf[BUFSIZ];
@@ -602,22 +849,41 @@ char *encode_cram_md5(char *challenge,char *user,char *secret)
secret == NULL || *secret == '\0')
return(NULL);
+ showVerbose("Server Challenge: %s\n",challenge);
OpenSSL_add_all_digests();
/* decode the challenge */
- data=mutils_decode_base64(challenge,strlen(challenge),&data_len);
+ data=mutils_decode_base64((unsigned char *) challenge,strlen(challenge),&data_len);
if (data == NULL)
{
errorMsg("Could not base64 decode CRAM-MD5 challenge: %s",challenge);
return(NULL);
}
+ showVerbose("Challenge After decoding: %s\n",data);
/* take HMAC-MD5 of the challenge*/
+
+#ifdef LIBRESSL_VERSION_NUMBER
md5=EVP_get_digestbyname("md5");
HMAC_CTX_init(&ctx);
HMAC_Init(&ctx,secret,strlen(secret),md5);
HMAC_Update(&ctx,data,data_len);
HMAC_Final(&ctx,hmac_md5,&hmac_len);
+#else
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+ md5=EVP_get_digestbyname("md5");
+ HMAC_CTX_init(&ctx);
+ HMAC_Init(&ctx,secret,strlen(secret),md5);
+ HMAC_Update(&ctx,data,data_len);
+ HMAC_Final(&ctx,hmac_md5,&hmac_len);
+#else
+ /* OpenSSL 1.1.x */
+ ctx = HMAC_CTX_new();
+ HMAC_Init_ex(ctx,secret,strlen(secret),EVP_md5(),NULL);
+ HMAC_Update(ctx,data,data_len);
+ HMAC_Final(ctx,hmac_md5,&hmac_len);
+#endif
+#endif /* LIBRESSL_VERSION_NUMBER */
/* convert the digest to hex */
memset(hex,0,sizeof(hex));
@@ -625,22 +891,36 @@ char *encode_cram_md5(char *challenge,char *user,char *secret)
{
(void) sprintf(hex+2*i,"%02x",hmac_md5[i]);
}
+ showVerbose("HMAC-MD5 of challenge: %s\n",hex);
(void) snprintf(buf,sizeof(buf)-1,"%s %s",user,hex);
+ showVerbose("base64 encode: %s\n",buf);
+ showVerbose("Taking base64 of \"%s\"\n",buf);
/* base64 encode "user hex_digest" */
- b64=mutils_encode_base64(buf,strlen(buf),&b64len);
+#if 0
+ b64=mutils_encode_base64((unsigned char *) buf,strlen(buf),&b64len);
if (b64len <= 0)
return(NULL);
/* mutils_encode_base64 adds CRLF */
if (b64len > 2)
b64[b64len-2]='\0';
+#endif
+ b64 = mutils_encode_base64_noformat(buf,strlen(buf));
+ if (b64 == NULL)
+ {
+ errorMsg("Could not base64 encode: %s",buf);
+ return (NULL);
+ }
+ showVerbose("base64: %s\n",b64);
+
return(b64);
}
#else
char *encode_cram_md5(char *challenge,char *user,char *secret)
{
- errorMsg("Must be compiled with OpenSSL in order to get CRAM-MD5 support\n");
+ errorMsg("Must be compiled with OpenSSL in order to get CRAM-MD5 support\n");
return(NULL);
}
#endif /* HAVE_OPENSSL */
+