summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2015-04-30 21:02:15 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2015-04-30 21:02:15 +0200
commit536cc69836d758ab7d156115ce296a3a25ce8aac (patch)
treeff24e7f4ed01a9343fe73f049defb4b93f201a5a
parenta3e26005fe00abe8836ba5dcdd1b9887ae6b1c27 (diff)
parent37dd84ec2145f500dce94fb136bd266b6445ae16 (diff)
downloadaCms-536cc69836d758ab7d156115ce296a3a25ce8aac.tar.gz
aCms-536cc69836d758ab7d156115ce296a3a25ce8aac.tar.bz2
Merge branch 'master' of ssh://git.andreasbaumann.cc/strusCms
-rw-r--r--3rdParty/CMakeLists.txt1
-rw-r--r--3rdParty/captcha/CMakeLists.txt26
-rw-r--r--3rdParty/libb64/CMakeLists.txt20
-rw-r--r--3rdParty/libquickmail/AUTHORS1
-rw-r--r--3rdParty/libquickmail/CMakeLists.txt28
-rw-r--r--3rdParty/libquickmail/COPYING674
-rw-r--r--3rdParty/libquickmail/quickmail.c1123
-rw-r--r--3rdParty/libquickmail/quickmail.h302
-rw-r--r--3rdParty/libquickmail/quickmailprog.c307
-rw-r--r--3rdParty/libquickmail/smtpsocket.c235
-rw-r--r--3rdParty/libquickmail/smtpsocket.h107
-rw-r--r--3rdParty/sha1/Makefile41
-rw-r--r--3rdParty/sha1/Makefile.nt48
-rw-r--r--3rdParty/sha1/license.txt14
-rw-r--r--3rdParty/sha1/sha.cpp176
-rw-r--r--3rdParty/sha1/sha1.cpp589
-rw-r--r--3rdParty/sha1/sha1.h89
-rw-r--r--3rdParty/sha1/shacmp.cpp169
-rw-r--r--3rdParty/sha1/shatest.cpp149
-rw-r--r--CMakeLists.txt6
-rw-r--r--TODOS3
-rw-r--r--config.js7
-rw-r--r--sql/sqlite3.sql23
-rw-r--r--src/mail.cpp53
-rw-r--r--src/mail.hpp33
-rw-r--r--src/sha1.cpp593
-rw-r--r--src/sha1.hpp93
-rw-r--r--src/strusCms.cpp8
-rw-r--r--src/strusCms.hpp3
-rw-r--r--src/user.cpp118
-rw-r--r--src/user.hpp7
-rw-r--r--templates/master.tmpl4
32 files changed, 5028 insertions, 22 deletions
diff --git a/3rdParty/CMakeLists.txt b/3rdParty/CMakeLists.txt
index 4b7aa4c..8f0aa9d 100644
--- a/3rdParty/CMakeLists.txt
+++ b/3rdParty/CMakeLists.txt
@@ -2,3 +2,4 @@ cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
add_subdirectory(captcha)
add_subdirectory(libb64)
+add_subdirectory(libquickmail)
diff --git a/3rdParty/captcha/CMakeLists.txt b/3rdParty/captcha/CMakeLists.txt
new file mode 100644
index 0000000..4e59b19
--- /dev/null
+++ b/3rdParty/captcha/CMakeLists.txt
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
+
+set(libcaptcha_source_files
+ captcha.c
+ f.h
+)
+
+set(unfont_source_files
+ unfont.c
+)
+
+if(NOT WIN32)
+ add_definitions("-fPIC")
+endif()
+
+add_custom_command(
+ PRE_BUILD
+ OUTPUT f.h
+ COMMAND ./unfont > f.h
+ DEPENDS unfont
+)
+
+add_executable(unfont ${unfont_source_files})
+
+add_library(captcha STATIC ${libcaptcha_source_files})
+
diff --git a/3rdParty/libb64/CMakeLists.txt b/3rdParty/libb64/CMakeLists.txt
new file mode 100644
index 0000000..ae4d3a9
--- /dev/null
+++ b/3rdParty/libb64/CMakeLists.txt
@@ -0,0 +1,20 @@
+cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
+
+set(libb64_source_files
+ src/cdecode.c
+ src/cencode.c
+)
+
+include_directories(
+ "include"
+)
+
+add_definitions(
+ "-DBUFFERSIZE=4096"
+)
+
+if(NOT WIN32)
+ add_definitions("-fPIC")
+endif()
+
+add_library(b64 STATIC ${libb64_source_files})
diff --git a/3rdParty/libquickmail/AUTHORS b/3rdParty/libquickmail/AUTHORS
new file mode 100644
index 0000000..56a21ea
--- /dev/null
+++ b/3rdParty/libquickmail/AUTHORS
@@ -0,0 +1 @@
+Brecht Sanders - brechtsanders@users.sourceforge.net
diff --git a/3rdParty/libquickmail/CMakeLists.txt b/3rdParty/libquickmail/CMakeLists.txt
new file mode 100644
index 0000000..c0b8fad
--- /dev/null
+++ b/3rdParty/libquickmail/CMakeLists.txt
@@ -0,0 +1,28 @@
+cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
+
+set(libquickmail_source_files
+ quickmail.c
+ smtpsocket.c
+)
+
+set(quickmailprog_source_files
+ quickmailprog.c
+)
+
+include_directories(
+ "."
+)
+
+#~ add_definitions(
+ #~ "-DNOCURL"
+#~ )
+
+if(NOT WIN32)
+ add_definitions("-fPIC")
+endif()
+
+add_executable(quickmailprog ${quickmailprog_source_files})
+
+target_link_libraries(quickmailprog quickmail curl)
+
+add_library(quickmail STATIC ${libquickmail_source_files})
diff --git a/3rdParty/libquickmail/COPYING b/3rdParty/libquickmail/COPYING
new file mode 100644
index 0000000..94a9ed0
--- /dev/null
+++ b/3rdParty/libquickmail/COPYING
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/3rdParty/libquickmail/quickmail.c b/3rdParty/libquickmail/quickmail.c
new file mode 100644
index 0000000..ab65535
--- /dev/null
+++ b/3rdParty/libquickmail/quickmail.c
@@ -0,0 +1,1123 @@
+/*
+ This file is part of libquickmail.
+
+ libquickmail is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ libquickmail is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libquickmail. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#if defined(_WIN32) && defined(DLL_EXPORT) && !defined(BUILD_QUICKMAIL_DLL)
+#define BUILD_QUICKMAIL_DLL
+#endif
+#include "quickmail.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+#if _MSC_VER
+#define snprintf _snprintf
+#define strdup _strdup
+#endif
+#ifndef NOCURL
+#if (defined(STATIC) || defined(BUILD_QUICKMAIL_STATIC)) && !defined(CURL_STATICLIB)
+#define CURL_STATICLIB
+#endif
+#include <curl/curl.h>
+#else
+#include "smtpsocket.h"
+#endif
+
+#define LIBQUICKMAIL_VERSION_MAJOR 0
+#define LIBQUICKMAIL_VERSION_MINOR 1
+#define LIBQUICKMAIL_VERSION_MICRO 18
+
+#define VERSION_STRINGIZE_(major, minor, micro) #major"."#minor"."#micro
+#define VERSION_STRINGIZE(major, minor, micro) VERSION_STRINGIZE_(major, minor, micro)
+
+#define LIBQUICKMAIL_VERSION VERSION_STRINGIZE(LIBQUICKMAIL_VERSION_MAJOR,LIBQUICKMAIL_VERSION_MINOR,LIBQUICKMAIL_VERSION_MICRO)
+
+#define NEWLINE "\r\n"
+#define NEWLINELENGTH 2
+//#define NEWLINE "\n"
+//#define NEWLINELENGTH 1
+
+#define MIME_LINE_WIDTH 72
+#define BODY_BUFFER_SIZE 256
+
+//definitions of the differen stages of generating the message data
+#define MAILPART_INITIALIZE 0
+#define MAILPART_HEADER 1
+#define MAILPART_BODY 2
+#define MAILPART_BODY_DONE 3
+#define MAILPART_ATTACHMENT 4
+#define MAILPART_END 5
+#define MAILPART_DONE 6
+
+static const char* default_mime_type = "text/plain";
+
+////////////////////////////////////////////////////////////////////////
+
+#define DEBUG_ERROR(errmsg)
+static const char* ERRMSG_MEMORY_ALLOCATION_ERROR = "Memory allocation error";
+
+////////////////////////////////////////////////////////////////////////
+
+char* randomize_zeros (char* data)
+{
+ //replace all 0s with random digits
+ char* p = data;
+ while (*p) {
+ if (*p == '0')
+ *p = '0' + rand() % 10;
+ p++;
+ }
+ return data;
+}
+
+char* str_append (char** data, const char* newdata)
+{
+ //append a string to the end of an existing string
+ char* p;
+ int len = (*data ? strlen(*data) : 0);
+ if ((p = (char*)realloc(*data, len + strlen(newdata) + 1)) == NULL) {
+ free(p);
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ return NULL;
+ }
+ *data = p;
+ strcpy(*data + len, newdata);
+ return *data;
+}
+
+////////////////////////////////////////////////////////////////////////
+
+struct email_info_struct {
+ int current; //must be zet to 0
+ time_t timestamp;
+ char* from;
+ struct email_info_email_list_struct* to;
+ struct email_info_email_list_struct* cc;
+ struct email_info_email_list_struct* bcc;
+ char* subject;
+ char* header;
+ struct email_info_attachment_list_struct* bodylist;
+ struct email_info_attachment_list_struct* attachmentlist;
+ char* buf;
+ int buflen;
+ char* mime_boundary_body;
+ char* mime_boundary_part;
+ struct email_info_attachment_list_struct* current_attachment;
+ FILE* debuglog;
+ char dtable[64];
+};
+
+////////////////////////////////////////////////////////////////////////
+
+struct email_info_email_list_struct {
+ char* data;
+ struct email_info_email_list_struct* next;
+};
+
+void email_info_string_list_add (struct email_info_email_list_struct** list, const char* data)
+{
+ struct email_info_email_list_struct** p = list;
+ while (*p)
+ p = &(*p)->next;
+ if ((*p = (struct email_info_email_list_struct*)malloc(sizeof(struct email_info_email_list_struct))) == NULL) {
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ return;
+ }
+ (*p)->data = (data ? strdup(data) : NULL);
+ (*p)->next = NULL;
+}
+
+void email_info_string_list_free (struct email_info_email_list_struct** list)
+{
+ struct email_info_email_list_struct* p = *list;
+ struct email_info_email_list_struct* current;
+ while (p) {
+ current = p;
+ p = current->next;
+ free(current->data);
+ free(current);
+ }
+ *list = NULL;
+}
+
+char* email_info_string_list_concatenate (struct email_info_email_list_struct* list)
+{
+ char* result = NULL;
+ struct email_info_email_list_struct* listentry = list;
+ while (listentry) {
+ if (listentry->data && *listentry->data) {
+ if (result)
+ str_append(&result, "," NEWLINE "\t");
+ str_append(&result, "<");
+ str_append(&result, listentry->data);
+ str_append(&result, ">");
+ }
+ listentry = listentry->next;
+ }
+ return result;
+}
+
+////////////////////////////////////////////////////////////////////////
+
+struct email_info_attachment_list_struct {
+ char* filename;
+ char* mimetype;
+ void* filedata;
+ void* handle;
+ quickmail_attachment_open_fn email_info_attachment_open;
+ quickmail_attachment_read_fn email_info_attachment_read;
+ quickmail_attachment_close_fn email_info_attachment_close;
+ quickmail_attachment_free_filedata_fn email_info_attachment_filedata_free;
+ struct email_info_attachment_list_struct* next;
+};
+
+struct email_info_attachment_list_struct* email_info_attachment_list_add (struct email_info_attachment_list_struct** list, const char* filename, const char* mimetype, void* filedata, quickmail_attachment_open_fn email_info_attachment_open, quickmail_attachment_read_fn email_info_attachment_read, quickmail_attachment_close_fn email_info_attachment_close, quickmail_attachment_free_filedata_fn email_info_attachment_filedata_free)
+{
+ struct email_info_attachment_list_struct** p = list;
+ while (*p)
+ p = &(*p)->next;
+ if ((*p = (struct email_info_attachment_list_struct*)malloc(sizeof(struct email_info_attachment_list_struct))) == NULL) {
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ return NULL;
+ }
+ (*p)->filename = strdup(filename ? filename : "UNNAMED");
+ (*p)->mimetype = (mimetype ? strdup(mimetype) : NULL);
+ (*p)->filedata = filedata;
+ (*p)->handle = NULL;
+ (*p)->email_info_attachment_open = email_info_attachment_open;
+ (*p)->email_info_attachment_read = email_info_attachment_read;
+ (*p)->email_info_attachment_close = email_info_attachment_close;
+ (*p)->email_info_attachment_filedata_free = email_info_attachment_filedata_free;
+ (*p)->next = NULL;
+ return *p;
+}
+
+void email_info_attachment_list_free_entry (struct email_info_attachment_list_struct* current)
+{
+ if (current->handle) {
+ if (current->email_info_attachment_close)
+ current->email_info_attachment_close(current->handle);
+ //else
+ // free(current->handle);
+ current->handle = NULL;
+ }
+ if (current->filedata) {
+ if (current->email_info_attachment_filedata_free)
+ current->email_info_attachment_filedata_free(current->filedata);
+ else
+ free(current->filedata);
+ }
+ if (current->mimetype)
+ free(current->mimetype);
+ free(current->filename);
+ free(current);
+}
+
+void email_info_attachment_list_free (struct email_info_attachment_list_struct** list)
+{
+ struct email_info_attachment_list_struct* p = *list;
+ struct email_info_attachment_list_struct* current;
+ while (p) {
+ current = p;
+ p = current->next;
+ email_info_attachment_list_free_entry(current);
+ }
+ *list = NULL;
+}
+
+int email_info_attachment_list_delete (struct email_info_attachment_list_struct** list, const char* filename)
+{
+ struct email_info_attachment_list_struct** p = list;
+ while (*p) {
+ if (strcmp((*p)->filename, filename) == 0) {
+ struct email_info_attachment_list_struct* current = *p;
+ *p = current->next;
+ email_info_attachment_list_free_entry(current);
+ return 0;
+ }
+ p = &(*p)->next;
+ }
+ return -1;
+}
+
+void email_info_attachment_list_close_handles (struct email_info_attachment_list_struct* list)
+{
+ struct email_info_attachment_list_struct* p = list;
+ while (p) {
+ if (p->handle) {
+ if (p->email_info_attachment_close)
+ p->email_info_attachment_close(p->handle);
+ //else
+ // free(p->handle);
+ p->handle = NULL;
+ }
+ p = p->next;
+ }
+}
+
+//dummy attachment functions
+
+void* email_info_attachment_open_dummy (void* filedata)
+{
+ return &email_info_attachment_open_dummy;
+}
+
+size_t email_info_attachment_read_dummy (void* handle, void* buf, size_t len)
+{
+ return 0;
+}
+
+struct email_info_attachment_list_struct* email_info_attachment_list_add_dummy (struct email_info_attachment_list_struct** list, const char* filename, const char* mimetype)
+{
+ return email_info_attachment_list_add(list, filename, mimetype, NULL, email_info_attachment_open_dummy, email_info_attachment_read_dummy, NULL, NULL);
+}
+
+//file attachment functions
+
+void* email_info_attachment_open_file (void* filedata)
+{
+ return (void*)fopen((char*)filedata, "rb");
+}
+
+size_t email_info_attachment_read_file (void* handle, void* buf, size_t len)
+{
+ return fread(buf, 1, len, (FILE*)handle);
+}
+
+void email_info_attachment_close_file (void* handle)
+{
+ if (handle)
+ fclose((FILE*)handle);
+}
+
+struct email_info_attachment_list_struct* email_info_attachment_list_add_file (struct email_info_attachment_list_struct** list, const char* path, const char* mimetype)
+{
+ //determine base filename
+ const char* basename = path + strlen(path);
+ while (basename != path) {
+ basename--;
+ if (*basename == '/'
+#ifdef _WIN32
+ || *basename == '\\' || *basename == ':'
+#endif
+ ) {
+ basename++;
+ break;
+ }
+ }
+ return email_info_attachment_list_add(list, basename, mimetype, (void*)strdup(path), email_info_attachment_open_file, email_info_attachment_read_file, email_info_attachment_close_file, NULL);
+}
+
+//memory attachment functions
+
+struct email_info_attachment_memory_filedata_struct {
+ char* data;
+ size_t datalen;
+ int mustfree;
+};
+
+struct email_info_attachment_memory_handle_struct {
+ const char* data;
+ size_t datalen;
+ size_t pos;
+};
+
+void* email_info_attachment_open_memory (void* filedata)
+{
+ struct email_info_attachment_memory_filedata_struct* data;
+ struct email_info_attachment_memory_handle_struct* result;
+ data = ((struct email_info_attachment_memory_filedata_struct*)filedata);
+ if (!data->data)
+ return NULL;
+ if ((result = (struct email_info_attachment_memory_handle_struct*)malloc(sizeof(struct email_info_attachment_memory_handle_struct))) == NULL) {
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ return NULL;
+ }
+ result->data = data->data;
+ result->datalen = data->datalen;
+ result->pos = 0;
+ return result;
+}
+
+size_t email_info_attachment_read_memory (void* handle, void* buf, size_t len)
+{
+ struct email_info_attachment_memory_handle_struct* h = (struct email_info_attachment_memory_handle_struct*)handle;
+ size_t n = (h->pos + len <= h->datalen ? len : h->datalen - h->pos);
+ memcpy(buf, h->data + h->pos, n);
+ h->pos += n;
+ return n;
+}
+
+void email_info_attachment_close_memory (void* handle)
+{
+ if (handle)
+ free(handle);
+}
+
+void email_info_attachment_filedata_free_memory (void* filedata)
+{
+ struct email_info_attachment_memory_filedata_struct* data = ((struct email_info_attachment_memory_filedata_struct*)filedata);
+ if (data) {
+ if (data->mustfree)
+ free(data->data);
+ free(data);
+ }
+}
+
+struct email_info_attachment_list_struct* email_info_attachment_list_add_memory (struct email_info_attachment_list_struct** list, const char* filename, const char* mimetype, char* data, size_t datalen, int mustfree)
+{
+ struct email_info_attachment_memory_filedata_struct* filedata;
+ if ((filedata = (struct email_info_attachment_memory_filedata_struct*)malloc(sizeof(struct email_info_attachment_memory_filedata_struct))) == NULL) {
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ return NULL;
+ }
+ filedata->data = data;
+ filedata->datalen = datalen;
+ filedata->mustfree = mustfree;
+ return email_info_attachment_list_add(list, filename, mimetype, filedata, email_info_attachment_open_memory, email_info_attachment_read_memory, email_info_attachment_close_memory, email_info_attachment_filedata_free_memory);
+}
+
+////////////////////////////////////////////////////////////////////////
+
+DLL_EXPORT_LIBQUICKMAIL const char* quickmail_get_version ()
+{
+ return VERSION_STRINGIZE(LIBQUICKMAIL_VERSION_MAJOR, LIBQUICKMAIL_VERSION_MINOR, LIBQUICKMAIL_VERSION_MICRO)
+#if defined(NOCURL)
+ "-light"
+#endif
+ ;
+}
+
+DLL_EXPORT_LIBQUICKMAIL int quickmail_initialize ()
+{
+#if defined(NOCURL) && defined(_WIN32)
+ static WSADATA wsaData;
+ int wsaerr = WSAStartup(MAKEWORD(1, 0), &wsaData);
+ if (wsaerr)
+ return -1;
+ atexit((void(*)())WSACleanup);
+#endif
+ return 0;
+}
+
+DLL_EXPORT_LIBQUICKMAIL quickmail quickmail_create (const char* from, const char* subject)
+{
+ int i;
+ struct email_info_struct* mailobj;
+ if ((mailobj = (struct email_info_struct*)malloc(sizeof(struct email_info_struct))) == NULL) {
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ return NULL;
+ }
+ mailobj->current = 0;
+ mailobj->timestamp = time(NULL);
+ mailobj->from = (from ? strdup(from) : NULL);
+ mailobj->to = NULL;
+ mailobj->cc = NULL;
+ mailobj->bcc = NULL;
+ mailobj->subject = (subject ? strdup(subject) : NULL);
+ mailobj->header = NULL;
+ mailobj->bodylist = NULL;
+ mailobj->attachmentlist = NULL;
+ mailobj->buf = NULL;
+ mailobj->buflen = 0;
+ mailobj->mime_boundary_body = NULL;
+ mailobj->mime_boundary_part = NULL;
+ mailobj->current_attachment = NULL;
+ mailobj->debuglog = NULL;
+ for (i = 0; i < 26; i++) {
+ mailobj->dtable[i] = (char)('A' + i);
+ mailobj->dtable[26 + i] = (char)('a' + i);
+ }
+ for (i = 0; i < 10; i++) {
+ mailobj->dtable[52 + i] = (char)('0' + i);
+ }
+ mailobj->dtable[62] = '+';
+ mailobj->dtable[63] = '/';
+ srand(time(NULL));
+ return mailobj;
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_destroy (quickmail mailobj)
+{
+ free(mailobj->from);
+ email_info_string_list_free(&mailobj->to);
+ email_info_string_list_free(&mailobj->cc);
+ email_info_string_list_free(&mailobj->bcc);
+ free(mailobj->subject);
+ free(mailobj->header);
+ email_info_attachment_list_free(&mailobj->bodylist);
+ email_info_attachment_list_free(&mailobj->attachmentlist);
+ free(mailobj->buf);
+ free(mailobj->mime_boundary_body);
+ free(mailobj->mime_boundary_part);
+ free(mailobj);
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_set_from (quickmail mailobj, const char* from)
+{
+ free(mailobj->from);
+ mailobj->from = strdup(from);
+}
+
+DLL_EXPORT_LIBQUICKMAIL const char* quickmail_get_from (quickmail mailobj)
+{
+ return mailobj->from;
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_to (quickmail mailobj, const char* email)
+{
+ email_info_string_list_add(&mailobj->to, email);
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_cc (quickmail mailobj, const char* email)
+{
+ email_info_string_list_add(&mailobj->cc, email);
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_bcc (quickmail mailobj, const char* email)
+{
+ email_info_string_list_add(&mailobj->bcc, email);
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_set_subject (quickmail mailobj, const char* subject)
+{
+ free(mailobj->subject);
+ mailobj->subject = (subject ? strdup(subject) : NULL);
+}
+
+DLL_EXPORT_LIBQUICKMAIL const char* quickmail_get_subject (quickmail mailobj)
+{
+ return mailobj->subject;
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_header (quickmail mailobj, const char* headerline)
+{
+ str_append(&mailobj->header, headerline);
+ str_append(&mailobj->header, NEWLINE);
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_set_body (quickmail mailobj, const char* body)
+{
+ email_info_attachment_list_free(&mailobj->bodylist);
+ if (body)
+ email_info_attachment_list_add_memory(&mailobj->bodylist, default_mime_type, default_mime_type, strdup(body), strlen(body), 1);
+}
+
+DLL_EXPORT_LIBQUICKMAIL char* quickmail_get_body (quickmail mailobj)
+{
+ size_t n;
+ char* p;
+ char* result = NULL;
+ size_t resultlen = 0;
+ if (mailobj->bodylist && (mailobj->bodylist->handle = mailobj->bodylist->email_info_attachment_open(mailobj->bodylist->filedata)) != NULL) {
+ do {
+ if ((p = (char*)realloc(result, resultlen + BODY_BUFFER_SIZE)) == NULL) {
+ free(result);
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ break;
+ }
+ result = p;
+ if ((n = mailobj->bodylist->email_info_attachment_read(mailobj->bodylist->handle, result + resultlen, BODY_BUFFER_SIZE)) > 0)
+ resultlen += n;
+ } while (n > 0);
+ if (mailobj->bodylist->email_info_attachment_close)
+ mailobj->bodylist->email_info_attachment_close(mailobj->bodylist->handle);
+ //else
+ // free(mailobj->bodylist->handle);
+ mailobj->bodylist->handle = NULL;
+ }
+ return result;
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_body_file (quickmail mailobj, const char* mimetype, const char* path)
+{
+ email_info_attachment_list_add(&mailobj->bodylist, (mimetype ? mimetype : default_mime_type), (mimetype ? mimetype : default_mime_type), (void*)strdup(path), email_info_attachment_open_file, email_info_attachment_read_file, email_info_attachment_close_file, NULL);
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_body_memory (quickmail mailobj, const char* mimetype, char* data, size_t datalen, int mustfree)
+{
+ email_info_attachment_list_add_memory(&mailobj->bodylist, (mimetype ? mimetype : default_mime_type), (mimetype ? mimetype : default_mime_type), data, datalen, mustfree);
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_body_custom (quickmail mailobj, const char* mimetype, char* data, quickmail_attachment_open_fn attachment_data_open, quickmail_attachment_read_fn attachment_data_read, quickmail_attachment_close_fn attachment_data_close, quickmail_attachment_free_filedata_fn attachment_data_filedata_free)
+{
+ email_info_attachment_list_add(&mailobj->bodylist, (mimetype ? mimetype : default_mime_type), (mimetype ? mimetype : default_mime_type), data, (attachment_data_open ? attachment_data_open : email_info_attachment_open_dummy), (attachment_data_read ? attachment_data_read : email_info_attachment_read_dummy), attachment_data_close, attachment_data_filedata_free);
+}
+
+DLL_EXPORT_LIBQUICKMAIL int quickmail_remove_body (quickmail mailobj, const char* mimetype)
+{
+ return email_info_attachment_list_delete(&mailobj->bodylist, mimetype);
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_list_bodies (quickmail mailobj, quickmail_list_attachment_callback_fn callback, void* callbackdata)
+{
+ struct email_info_attachment_list_struct* p = mailobj->bodylist;
+ while (p) {
+ callback(mailobj, p->filename, p->mimetype, p->email_info_attachment_open, p->email_info_attachment_read, p->email_info_attachment_close, callbackdata);
+ p = p->next;
+ }
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_attachment_file (quickmail mailobj, const char* path, const char* mimetype)
+{
+ email_info_attachment_list_add_file(&mailobj->attachmentlist, path, mimetype);
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_attachment_memory (quickmail mailobj, const char* filename, const char* mimetype, char* data, size_t datalen, int mustfree)
+{
+ email_info_attachment_list_add_memory(&mailobj->attachmentlist, filename, mimetype, data, datalen, mustfree);
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_attachment_custom (quickmail mailobj, const char* filename, const char* mimetype, char* data, quickmail_attachment_open_fn attachment_data_open, quickmail_attachment_read_fn attachment_data_read, quickmail_attachment_close_fn attachment_data_close, quickmail_attachment_free_filedata_fn attachment_data_filedata_free)
+{
+ email_info_attachment_list_add(&mailobj->attachmentlist, filename, mimetype, data, (attachment_data_open ? attachment_data_open : email_info_attachment_open_dummy), (attachment_data_read ? attachment_data_read : email_info_attachment_read_dummy), attachment_data_close, attachment_data_filedata_free);
+}
+
+DLL_EXPORT_LIBQUICKMAIL int quickmail_remove_attachment (quickmail mailobj, const char* filename)
+{
+ return email_info_attachment_list_delete(&mailobj->attachmentlist, filename);
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_list_attachments (quickmail mailobj, quickmail_list_attachment_callback_fn callback, void* callbackdata)
+{
+ struct email_info_attachment_list_struct* p = mailobj->attachmentlist;
+ while (p) {
+ callback(mailobj, p->filename, p->mimetype, p->email_info_attachment_open, p->email_info_attachment_read, p->email_info_attachment_close, callbackdata);
+ p = p->next;
+ }
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_set_debug_log (quickmail mailobj, FILE* filehandle)
+{
+ mailobj->debuglog = filehandle;
+}
+
+DLL_EXPORT_LIBQUICKMAIL void quickmail_fsave (quickmail mailobj, FILE* filehandle)
+{
+ int i;
+ size_t n;
+ char buf[80];
+ while ((n = quickmail_get_data(buf, sizeof(buf), 1, mailobj)) > 0) {
+ for (i = 0; i < n; i++)
+ fprintf(filehandle, "%c", buf[i]);
+ }
+}
+
+DLL_EXPORT_LIBQUICKMAIL size_t quickmail_get_data (void* ptr, size_t size, size_t nmemb, void* userp)
+{
+ struct email_info_struct* mailobj = (struct email_info_struct*)userp;
+
+ //abort if no data is requested
+ if (size * nmemb == 0)
+ return 0;
+
+ //initialize on first run
+ if (mailobj->current == MAILPART_INITIALIZE) {
+ free(mailobj->buf);
+ mailobj->buf = NULL;
+ mailobj->buflen = 0;
+ free(mailobj->mime_boundary_body);
+ mailobj->mime_boundary_body = NULL;
+ free(mailobj->mime_boundary_part);
+ mailobj->mime_boundary_part = NULL;
+ mailobj->current_attachment = mailobj->bodylist;
+ mailobj->current++;
+ }
+
+ //process current part of mail if no partial data is pending
+ while (mailobj->buflen == 0) {
+ if (mailobj->buflen == 0 && mailobj->current == MAILPART_HEADER) {
+ char* s;
+ //generate header part
+ char** p = &mailobj->buf;
+ mailobj->buf = NULL;
+ str_append(p, "User-Agent: libquickmail v" LIBQUICKMAIL_VERSION NEWLINE);
+ if (mailobj->timestamp != 0) {
+ char timestamptext[32];
+ if (strftime(timestamptext, sizeof(timestamptext), "%a, %d %b %Y %H:%M:%S %z", localtime(&mailobj->timestamp))) {
+ str_append(p, "Date: ");
+ str_append(p, timestamptext);
+ str_append(p, NEWLINE);
+ }
+#ifdef _WIN32
+ //fallback method for Windows when %z (time zone offset) fails
+ else if (strftime(timestamptext, sizeof(timestamptext), "%a, %d %b %Y %H:%M:%S", localtime(&mailobj->timestamp))) {
+ TIME_ZONE_INFORMATION tzinfo;
+ if (GetTimeZoneInformation(&tzinfo) != TIME_ZONE_ID_INVALID)
+ sprintf(timestamptext + strlen(timestamptext), " %c%02i%02i", (tzinfo.Bias > 0 ? '-' : '+'), (int)-tzinfo.Bias / 60, (int)-tzinfo.Bias % 60);
+ str_append(p, "Date: ");
+ str_append(p, timestamptext);
+ str_append(p, NEWLINE);
+ }
+#endif
+ }
+ if (mailobj->from && *mailobj->from) {
+ str_append(p, "From: <");
+ str_append(p, mailobj->from);
+ str_append(p, ">" NEWLINE);
+ }
+ if ((s = email_info_string_list_concatenate(mailobj->to)) != NULL) {
+ str_append(p, "To: ");
+ str_append(p, s);
+ str_append(p, NEWLINE);
+ free(s);
+ }
+ if ((s = email_info_string_list_concatenate(mailobj->cc)) != NULL) {
+ str_append(p, "Cc: ");
+ str_append(p, s);
+ str_append(p, NEWLINE);
+ free(s);
+ }
+ if (mailobj->subject) {
+ str_append(p, "Subject: ");
+ str_append(p, mailobj->subject);
+ str_append(p, NEWLINE);
+ }
+ if (mailobj->header) {
+ str_append(p, mailobj->header);
+ }
+ if (mailobj->attachmentlist) {
+ str_append(p, "MIME-Version: 1.0" NEWLINE);
+ }
+ if (mailobj->attachmentlist) {
+ mailobj->mime_boundary_part = randomize_zeros(strdup("=PART=SEPARATOR=_0000_0000_0000_0000_0000_0000_="));
+ str_append(p, "Content-Type: multipart/mixed; boundary=\"");
+ str_append(p, mailobj->mime_boundary_part);
+ str_append(p, "\"" NEWLINE NEWLINE "This is a multipart message in MIME format." NEWLINE NEWLINE "--");
+ str_append(p, mailobj->mime_boundary_part);
+ str_append(p, NEWLINE);
+ }
+ if (mailobj->bodylist && mailobj->bodylist->next) {
+ mailobj->mime_boundary_body = randomize_zeros(strdup("=BODY=SEPARATOR=_0000_0000_0000_0000_0000_0000_="));
+ str_append(p, "Content-Type: multipart/alternative; boundary=\"");
+ str_append(p, mailobj->mime_boundary_body);
+ str_append(p, NEWLINE);
+ }
+ mailobj->buflen = strlen(mailobj->buf);
+ mailobj->current++;
+ }
+ if (mailobj->buflen == 0 && mailobj->current == MAILPART_BODY) {
+ if (mailobj->current_attachment) {
+ if (!mailobj->current_attachment->handle) {
+ //open file with body data
+ while (mailobj->current_attachment) {
+ if ((mailobj->current_attachment->handle = mailobj->current_attachment->email_info_attachment_open(mailobj->current_attachment->filedata)) != NULL) {
+ break;
+ }
+ mailobj->current_attachment = mailobj->current_attachment->next;
+ }
+ if (!mailobj->current_attachment) {
+ mailobj->current_attachment = mailobj->attachmentlist;
+ mailobj->current++;
+ }
+ //generate attachment header
+ if (mailobj->current_attachment && mailobj->current_attachment->handle) {
+ mailobj->buf = NULL;
+ if (mailobj->mime_boundary_body) {
+ mailobj->buf = str_append(&mailobj->buf, NEWLINE "--");
+ mailobj->buf = str_append(&mailobj->buf, mailobj->mime_boundary_body);
+ mailobj->buf = str_append(&mailobj->buf, NEWLINE);
+ }
+ mailobj->buf = str_append(&mailobj->buf, "Content-Type: ");
+ mailobj->buf = str_append(&mailobj->buf, (mailobj->bodylist && mailobj->current_attachment->filename ? mailobj->current_attachment->filename : default_mime_type));
+ mailobj->buf = str_append(&mailobj->buf, NEWLINE "Content-Transfer-Encoding: 8bit" NEWLINE "Content-Disposition: inline" NEWLINE NEWLINE);
+ mailobj->buflen = strlen(mailobj->buf);
+ }
+ }
+ if (mailobj->buflen == 0 && mailobj->current_attachment && mailobj->current_attachment->handle) {
+ //read body data
+ if ((mailobj->buf = malloc(BODY_BUFFER_SIZE)) == NULL) {
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ }
+ if (mailobj->buf == NULL || (mailobj->buflen = mailobj->current_attachment->email_info_attachment_read(mailobj->current_attachment->handle, mailobj->buf, BODY_BUFFER_SIZE)) <= 0) {
+ //end of file
+ free(mailobj->buf);
+ mailobj->buflen = 0;
+ if (mailobj->current_attachment->email_info_attachment_close)
+ mailobj->current_attachment->email_info_attachment_close(mailobj->current_attachment->handle);
+ //else
+ // free(mailobj->current_attachment->handle);
+ mailobj->current_attachment->handle = NULL;
+ mailobj->current_attachment = mailobj->current_attachment->next;
+ }
+ }
+ } else {
+ mailobj->current_attachment = mailobj->attachmentlist;
+ mailobj->current++;
+ }
+ }
+ if (mailobj->buflen == 0 && mailobj->current == MAILPART_BODY_DONE) {
+ mailobj->buf = NULL;
+ if (mailobj->mime_boundary_body) {
+ mailobj->buf = str_append(&mailobj->buf, NEWLINE "--");
+ mailobj->buf = str_append(&mailobj->buf, mailobj->mime_boundary_body);
+ mailobj->buf = str_append(&mailobj->buf, "--" NEWLINE);
+ mailobj->buflen = strlen(mailobj->buf);
+ free(mailobj->mime_boundary_body);
+ mailobj->mime_boundary_body = NULL;
+ }
+ mailobj->current++;
+ }
+ if (mailobj->buflen == 0 && mailobj->current == MAILPART_ATTACHMENT) {
+ if (mailobj->current_attachment) {
+ if (!mailobj->current_attachment->handle) {
+ //open file to attach
+ while (mailobj->current_attachment) {
+ if ((mailobj->current_attachment->handle = mailobj->current_attachment->email_info_attachment_open(mailobj->current_attachment->filedata)) != NULL) {
+ break;
+ }
+ mailobj->current_attachment = mailobj->current_attachment->next;
+ }
+ //generate attachment header
+ if (mailobj->current_attachment && mailobj->current_attachment->handle) {
+ mailobj->buf = NULL;
+ if (mailobj->mime_boundary_part) {
+ mailobj->buf = str_append(&mailobj->buf, NEWLINE "--");
+ mailobj->buf = str_append(&mailobj->buf, mailobj->mime_boundary_part);
+ mailobj->buf = str_append(&mailobj->buf, NEWLINE);
+ }
+ mailobj->buf = str_append(&mailobj->buf, "Content-Type: ");
+ mailobj->buf = str_append(&mailobj->buf, (mailobj->current_attachment->mimetype ? mailobj->current_attachment->mimetype : "application/octet-stream"));
+ mailobj->buf = str_append(&mailobj->buf, "; Name=\"");
+ mailobj->buf = str_append(&mailobj->buf, mailobj->current_attachment->filename);
+ mailobj->buf = str_append(&mailobj->buf, "\"" NEWLINE "Content-Transfer-Encoding: base64" NEWLINE NEWLINE);
+ mailobj->buflen = strlen(mailobj->buf);
+ }
+ } else {
+ //generate next line of attachment data
+ size_t n = 0;
+ int mimelinepos = 0;
+ unsigned char igroup[3] = {0, 0, 0};
+ unsigned char ogroup[4];
+ mailobj->buflen = 0;
+ if ((mailobj->buf = (char*)malloc(MIME_LINE_WIDTH + NEWLINELENGTH + 1)) == NULL) {
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ n = 0;
+ } else {
+ while (mimelinepos < MIME_LINE_WIDTH && (n = mailobj->current_attachment->email_info_attachment_read(mailobj->current_attachment->handle, igroup, 3)) > 0) {
+ //code data
+ ogroup[0] = mailobj->dtable[igroup[0] >> 2];
+ ogroup[1] = mailobj->dtable[((igroup[0] & 3) << 4) | (igroup[1] >> 4)];
+ ogroup[2] = mailobj->dtable[((igroup[1] & 0xF) << 2) | (igroup[2] >> 6)];
+ ogroup[3] = mailobj->dtable[igroup[2] & 0x3F];
+ //padd with "=" characters if less than 3 characters were read
+ if (n < 3) {
+ ogroup[3] = '=';
+ if (n < 2)
+ ogroup[2] = '=';
+ }
+ memcpy(mailobj->buf + mimelinepos, ogroup, 4);
+ mailobj->buflen += 4;
+ mimelinepos += 4;
+ }
+ if (mimelinepos > 0) {
+ memcpy(mailobj->buf + mimelinepos, NEWLINE, NEWLINELENGTH);
+ mailobj->buflen += NEWLINELENGTH;
+ }
+ }
+ if (n <= 0) {
+ //end of file
+ if (mailobj->current_attachment->email_info_attachment_close)
+ mailobj->current_attachment->email_info_attachment_close(mailobj->current_attachment->handle);
+ else
+ free(mailobj->current_attachment->handle);
+ mailobj->current_attachment->handle = NULL;
+ mailobj->current_attachment = mailobj->current_attachment->next;
+ }
+ }
+ } else {
+ mailobj->current++;
+ }
+ }
+ if (mailobj->buflen == 0 && mailobj->current == MAILPART_END) {
+ mailobj->buf = NULL;
+ mailobj->buflen = 0;
+ if (mailobj->mime_boundary_part) {
+ mailobj->buf = str_append(&mailobj->buf, NEWLINE "--");
+ mailobj->buf = str_append(&mailobj->buf, mailobj->mime_boundary_part);
+ mailobj->buf = str_append(&mailobj->buf, "--" NEWLINE);
+ mailobj->buflen = strlen(mailobj->buf);
+ free(mailobj->mime_boundary_part);
+ mailobj->mime_boundary_part = NULL;
+ }
+ //mailobj->buf = str_append(&mailobj->buf, NEWLINE "." NEWLINE);
+ //mailobj->buflen = strlen(mailobj->buf);
+ mailobj->current++;
+ }
+ if (mailobj->buflen == 0 && mailobj->current == MAILPART_DONE) {
+ break;
+ }
+ }
+
+ //flush pending data if any
+ if (mailobj->buflen > 0) {
+ int len = (mailobj->buflen > size * nmemb ? size * nmemb : mailobj->buflen);
+ memcpy(ptr, mailobj->buf, len);
+ if (len < mailobj->buflen) {
+ mailobj->buf = memmove(mailobj->buf, mailobj->buf + len, mailobj->buflen - len);
+ mailobj->buflen -= len;
+ } else {
+ free(mailobj->buf);
+ mailobj->buf = NULL;
+ mailobj->buflen = 0;
+ }
+ return len;
+ }
+
+ //if (mailobj->current != MAILPART_DONE)
+ // ;//this should never be reached
+ mailobj->current = 0;
+ return 0;
+}
+
+#ifndef NOCURL
+char* add_angle_brackets (const char* data)
+{
+ size_t datalen = strlen(data);
+ char* result;
+ if ((result = (char*)malloc(datalen + 3)) == NULL) {
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ return NULL;
+ }
+ result[0] = '<';
+ memcpy(result + 1, data, datalen);
+ result[datalen + 1] = '>';
+ result[datalen + 2] = 0;
+ return result;
+}
+#endif
+
+DLL_EXPORT_LIBQUICKMAIL const char* quickmail_send (quickmail mailobj, const char* smtpserver, unsigned int smtpport, const char* username, const char* password)
+{
+#ifndef NOCURL
+ //libcurl based sending
+ CURL *curl;
+ CURLcode result = CURLE_FAILED_INIT;
+ //curl_global_init(CURL_GLOBAL_ALL);
+ if ((curl = curl_easy_init()) != NULL) {
+ struct curl_slist *recipients = NULL;
+ struct email_info_email_list_struct* listentry;
+ //set destination URL
+ char* addr;
+ size_t len = strlen(smtpserver) + 14;
+ if ((addr = (char*)malloc(len)) == NULL) {
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ return ERRMSG_MEMORY_ALLOCATION_ERROR;
+ }
+ snprintf(addr, len, "smtp://%s:%u", smtpserver, smtpport);
+ curl_easy_setopt(curl, CURLOPT_URL, addr);
+ free(addr);
+ //try Transport Layer Security (TLS), but continue anyway if it fails
+ curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_TRY);
+ //don't fail if the TLS/SSL a certificate could not be verified
+ //alternative: add the issuer certificate (or the host certificate if
+ //the certificate is self-signed) to the set of certificates that are
+ //known to libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
+ //set authentication credentials if provided
+ if (username && *username)
+ curl_easy_setopt(curl, CURLOPT_USERNAME, username);
+ if (password)
+ curl_easy_setopt(curl, CURLOPT_PASSWORD, password);
+ //set from value for envelope reverse-path
+ if (mailobj->from && *mailobj->from) {
+ addr = add_angle_brackets(mailobj->from);
+ curl_easy_setopt(curl, CURLOPT_MAIL_FROM, addr);
+ free(addr);
+ }
+ //set recipients
+ listentry = mailobj->to;
+ while (listentry) {
+ if (listentry->data && *listentry->data) {
+ addr = add_angle_brackets(listentry->data);
+ recipients = curl_slist_append(recipients, addr);
+ free(addr);
+ }
+ listentry = listentry->next;
+ }
+ listentry = mailobj->cc;
+ while (listentry) {
+ if (listentry->data && *listentry->data) {
+ addr = add_angle_brackets(listentry->data);
+ recipients = curl_slist_append(recipients, addr);
+ free(addr);
+ }
+ listentry = listentry->next;
+ }
+ listentry = mailobj->bcc;
+ while (listentry) {
+ if (listentry->data && *listentry->data) {
+ addr = add_angle_brackets(listentry->data);
+ recipients = curl_slist_append(recipients, addr);
+ free(addr);
+ }
+ listentry = listentry->next;
+ }
+ curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
+ //set callback function for getting message body
+ curl_easy_setopt(curl, CURLOPT_READFUNCTION, quickmail_get_data);
+ curl_easy_setopt(curl, CURLOPT_READDATA, mailobj);
+ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+ //enable debugging if requested
+ if (mailobj->debuglog) {
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+ curl_easy_setopt(curl, CURLOPT_STDERR, mailobj->debuglog);
+ }
+ //send the message
+ result = curl_easy_perform(curl);
+ //free the list of recipients and clean up
+ curl_slist_free_all(recipients);
+ curl_easy_cleanup(curl);
+ }
+ return (result == CURLE_OK ? NULL : curl_easy_strerror(result));
+#else
+ //minimal implementation without libcurl
+ SOCKET sock;
+ char* errmsg = NULL;
+ struct email_info_email_list_struct* listentry;
+ char local_hostname[64];
+ int statuscode;
+ //determine local host name
+ if (gethostname(local_hostname, sizeof(local_hostname)) != 0)
+ strcpy(local_hostname, "localhost");
+ //connect
+ if ((sock = socket_open(smtpserver, smtpport, &errmsg)) != INVALID_SOCKET) {
+ //talk with SMTP server
+ if ((statuscode = socket_smtp_command(sock, mailobj->debuglog, NULL)) >= 400) {
+ errmsg = "SMTP server returned an error on connection";
+ } else {
+ size_t n;
+ char buf[WRITE_BUFFER_CHUNK_SIZE];
+ do {
+ if ((statuscode = socket_smtp_command(sock, mailobj->debuglog, "EHLO %s", local_hostname)) >= 400) {
+ if ((statuscode = socket_smtp_command(sock, mailobj->debuglog, "HELO %s", local_hostname)) >= 400) {
+ errmsg = "SMTP EHLO/HELO returned error";
+ break;
+ }
+ }
+ //authenticate if needed
+ if (username || password) {
+ int len;
+ int inpos = 0;
+ int outpos = 0;
+ size_t usernamelen = (username ? strlen(username) : 0);
+ size_t passwordlen = (password ? strlen(password) : 0);
+ char* auth;
+ char* base64auth;
+ if ((auth = (char*)malloc(usernamelen + passwordlen + 4)) == NULL) {
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ return ERRMSG_MEMORY_ALLOCATION_ERROR;
+ }
+ if ((base64auth = (char*)malloc(((usernamelen + passwordlen + 2) + 2) / 3 * 4 + 1)) == NULL) {
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ return ERRMSG_MEMORY_ALLOCATION_ERROR;
+ }
+ //leave the authorization identity empty to indicate it's the same the as authentication identity
+ auth[0] = 0;
+ len = 1;
+ //set the authentication identity
+ memcpy(auth + len, (username ? username : ""), usernamelen + 1);
+ len += usernamelen + 1;
+ //set the password
+ memcpy(auth + len, (password ? password : ""), passwordlen + 1);
+ len += passwordlen;
+ //padd with extra zero so groups of 3 bytes can be read
+ auth[usernamelen + len + 1] = 0;
+ //encode in base64
+ while (inpos < len) {
+ //encode data
+ base64auth[outpos + 0] = mailobj->dtable[auth[inpos + 0] >> 2];
+ base64auth[outpos + 1] = mailobj->dtable[((auth[inpos + 0] & 3) << 4) | (auth[inpos + 1] >> 4)];
+ base64auth[outpos + 2] = mailobj->dtable[((auth[inpos + 1] & 0xF) << 2) | (auth[inpos + 2] >> 6)];
+ base64auth[outpos + 3] = mailobj->dtable[auth[inpos + 2] & 0x3F];
+ //padd with "=" characters if less than 3 characters were read
+ if (inpos + 1 >= len) {
+ base64auth[outpos + 3] = '=';
+ if (inpos + 2 >= len)
+ base64auth[outpos + 2] = '=';
+ }
+ //advance to next position
+ inpos += 3;
+ outpos += 4;
+ }
+ base64auth[outpos] = 0;
+ //send originator e-mail address
+ fprintf( stderr, "AUTH PLAIN %s\n", base64auth );
+ if ((statuscode = socket_smtp_command(sock, mailobj->debuglog, "AUTH PLAIN %s", base64auth)) >= 400) {
+ errmsg = "SMTP authentication failed";
+ break;
+ }
+ }
+ //send originator e-mail address
+ if ((statuscode = socket_smtp_command(sock, mailobj->debuglog, "MAIL FROM:<%s>", mailobj->from)) >= 400) {
+ errmsg = "SMTP server did not accept sender";
+ break;
+ }
+ //send recipient e-mail addresses
+ listentry = mailobj->to;
+ while (!errmsg && listentry) {
+ if (listentry->data && *listentry->data) {
+ if ((statuscode = socket_smtp_command(sock, mailobj->debuglog, "RCPT TO:<%s>", listentry->data)) >= 400)
+ errmsg = "SMTP server did not accept e-mail address (To)";
+ }
+ listentry = listentry->next;
+ }
+ listentry = mailobj->cc;
+ while (!errmsg && listentry) {
+ if (listentry->data && *listentry->data) {
+ if ((statuscode = socket_smtp_command(sock, mailobj->debuglog, "RCPT TO:<%s>", listentry->data)) >= 400)
+ errmsg = "SMTP server did not accept e-mail address (CC)";
+ }
+ listentry = listentry->next;
+ }
+ listentry = mailobj->bcc;
+ while (!errmsg && listentry) {
+ if (listentry->data && *listentry->data) {
+ if ((statuscode = socket_smtp_command(sock, mailobj->debuglog, "RCPT TO:<%s>", listentry->data)) >= 400)
+ errmsg = "SMTP server did not accept e-mail address (BCC)";
+ }
+ listentry = listentry->next;
+ }
+ if (errmsg)
+ break;
+ //prepare to send mail body
+ if ((statuscode = socket_smtp_command(sock, mailobj->debuglog, "DATA")) >= 400) {
+ errmsg = "SMTP DATA returned error";
+ break;
+ }
+ //send mail body data
+ while ((n = quickmail_get_data(buf, sizeof(buf), 1, mailobj)) > 0) {
+ socket_send(sock, buf, n);
+ }
+ //send end of data
+ if ((statuscode = socket_smtp_command(sock, mailobj->debuglog, "\r\n.")) >= 400) {
+ errmsg = "SMTP error after sending message data";
+ break;
+ }
+ } while (0);
+ //log out
+ socket_smtp_command(sock, mailobj->debuglog, "QUIT");
+ }
+ }
+ //close socket
+ socket_close(sock);
+ return errmsg;
+#endif
+}
diff --git a/3rdParty/libquickmail/quickmail.h b/3rdParty/libquickmail/quickmail.h
new file mode 100644
index 0000000..a61a913
--- /dev/null
+++ b/3rdParty/libquickmail/quickmail.h
@@ -0,0 +1,302 @@
+/*! \file quickmail.h
+ * \brief header file for libquickmail
+ * \author Brecht Sanders
+ * \date 2012-2013
+ * \copyright GPL
+ */
+/*
+ This file is part of libquickmail.
+
+ libquickmail is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ libquickmail is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libquickmail. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __INCLUDED_QUICKMAIL_H
+#define __INCLUDED_QUICKMAIL_H
+
+#include <stdio.h>
+
+/*! \brief define for exporting/importing functions in/from shared library */
+#ifdef _WIN32
+#if defined(BUILD_QUICKMAIL_DLL)
+#define DLL_EXPORT_LIBQUICKMAIL __declspec(dllexport)
+#elif !defined(STATIC) && !defined(BUILD_QUICKMAIL_STATIC)
+#define DLL_EXPORT_LIBQUICKMAIL __declspec(dllimport)
+#else
+#define DLL_EXPORT_LIBQUICKMAIL
+#endif
+#else
+#define DLL_EXPORT_LIBQUICKMAIL
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*! \brief quickmail object type */
+typedef struct email_info_struct* quickmail;
+
+
+
+/*! \brief type of pointer to function for opening attachment data
+ * \param filedata custom data as passed to quickmail_add_body_custom/quickmail_add_attachment_custom
+ * \return data structure to be used in calls to quickmail_attachment_read_fn and quickmail_attachment_close_fn functions
+ * \sa quickmail_add_body_custom()
+ * \sa quickmail_add_attachment_custom()
+ */
+typedef void* (*quickmail_attachment_open_fn)(void* filedata);
+
+/*! \brief type of pointer to function for reading attachment data
+ * \param handle data structure obtained via the corresponding quickmail_attachment_open_fn function
+ * \param buf buffer for receiving data
+ * \param len size in bytes of buffer for receiving data
+ * \return number of bytes read (zero on end of file)
+ * \sa quickmail_add_body_custom()
+ * \sa quickmail_add_attachment_custom()
+ */
+typedef size_t (*quickmail_attachment_read_fn)(void* handle, void* buf, size_t len);
+
+/*! \brief type of pointer to function for closing attachment data
+ * \param handle data structure obtained via the corresponding quickmail_attachment_open_fn function
+ * \sa quickmail_add_body_custom()
+ * \sa quickmail_add_attachment_custom()
+ */
+typedef void (*quickmail_attachment_close_fn)(void* handle);
+
+/*! \brief type of pointer to function for cleaning up custom data in quickmail_destroy
+ * \param filedata custom data as passed to quickmail_add_body_custom/quickmail_add_attachment_custom
+ * \sa quickmail_add_body_custom()
+ * \sa quickmail_add_attachment_custom()
+ */
+typedef void (*quickmail_attachment_free_filedata_fn)(void* filedata);
+
+/*! \brief type of pointer to function for cleaning up custom data in quickmail_destroy
+ * \param mailobj quickmail object
+ * \param filename attachment filename (same value as mimetype for mail body)
+ * \param mimetype MIME type
+ * \param attachment_data_open function for opening attachment data
+ * \param attachment_data_read function for reading attachment data
+ * \param attachment_data_close function for closing attachment data (optional, free() will be used if NULL)
+ * \param callbackdata custom data passed to quickmail_list_attachments
+ * \sa quickmail_list_bodies()
+ * \sa quickmail_list_attachments()
+ */
+typedef void (*quickmail_list_attachment_callback_fn)(quickmail mailobj, const char* filename, const char* mimetype, quickmail_attachment_open_fn email_info_attachment_open, quickmail_attachment_read_fn email_info_attachment_read, quickmail_attachment_close_fn email_info_attachment_close, void* callbackdata);
+
+
+
+/*! \brief get version quickmail library
+ * \return library version
+ */
+DLL_EXPORT_LIBQUICKMAIL const char* quickmail_get_version ();
+
+/*! \brief initialize quickmail library
+ * \return zero on success
+ */
+DLL_EXPORT_LIBQUICKMAIL int quickmail_initialize ();
+
+/*! \brief create a new quickmail object
+ * \param from sender e-mail address
+ * \param subject e-mail subject
+ * \return quickmail object or NULL on error
+ */
+DLL_EXPORT_LIBQUICKMAIL quickmail quickmail_create (const char* from, const char* subject);
+
+/*! \brief clean up a quickmail object
+ * \param mailobj quickmail object
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_destroy (quickmail mailobj);
+
+/*! \brief set the sender (from) e-mail address of a quickmail object
+ * \param mailobj quickmail object
+ * \param from sender e-mail address
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_set_from (quickmail mailobj, const char* from);
+
+/*! \brief get the sender (from) e-mail address of a quickmail object
+ * \param mailobj quickmail object
+ * \return sender e-mail address
+ */
+DLL_EXPORT_LIBQUICKMAIL const char* quickmail_get_from (quickmail mailobj);
+
+/*! \brief add a recipient (to) e-mail address to a quickmail object
+ * \param mailobj quickmail object
+ * \param e-mail recipient e-mail address
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_to (quickmail mailobj, const char* email);
+
+/*! \brief add a carbon copy recipient (cc) e-mail address to a quickmail object
+ * \param mailobj quickmail object
+ * \param e-mail recipient e-mail address
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_cc (quickmail mailobj, const char* email);
+
+/*! \brief add a blind carbon copy recipient (bcc) e-mail address to a quickmail object
+ * \param mailobj quickmail object
+ * \param e-mail recipient e-mail address
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_bcc (quickmail mailobj, const char* email);
+
+/*! \brief set the subject of a quickmail object
+ * \param mailobj quickmail object
+ * \param subject e-mail subject
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_set_subject (quickmail mailobj, const char* subject);
+
+/*! \brief set the subject of a quickmail object
+ * \param mailobj quickmail object
+ * \return e-mail subject
+ */
+DLL_EXPORT_LIBQUICKMAIL const char* quickmail_get_subject (quickmail mailobj);
+
+/*! \brief add an e-mail header to a quickmail object
+ * \param mailobj quickmail object
+ * \param headerline header line to add
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_header (quickmail mailobj, const char* headerline);
+
+/*! \brief set the body of a quickmail object
+ * \param mailobj quickmail object
+ * \param body e-mail body
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_set_body (quickmail mailobj, const char* body);
+
+/*! \brief set the body of a quickmail object
+ * any existing bodies will be removed and a single plain text body will be added
+ * \param mailobj quickmail object
+ * \return e-mail body or NULL on error (caller must free result)
+ */
+DLL_EXPORT_LIBQUICKMAIL char* quickmail_get_body (quickmail mailobj);
+
+/*! \brief add a body file to a quickmail object (deprecated)
+ * \param mailobj quickmail object
+ * \param mimetype MIME type (text/plain will be used if set to NULL)
+ * \param path path of file with body data
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_body_file (quickmail mailobj, const char* mimetype, const char* path);
+
+/*! \brief add a body from memory to a quickmail object
+ * \param mailobj quickmail object
+ * \param mimetype MIME type (text/plain will be used if set to NULL)
+ * \param data body content
+ * \param datalen size of data in bytes
+ * \param mustfree non-zero if data must be freed by quickmail_destroy
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_body_memory (quickmail mailobj, const char* mimetype, char* data, size_t datalen, int mustfree);
+
+/*! \brief add a body with custom read functions to a quickmail object
+ * \param mailobj quickmail object
+ * \param mimetype MIME type (text/plain will be used if set to NULL)
+ * \param data custom data passed to attachment_data_open and attachment_data_filedata_free functions
+ * \param attachment_data_open function for opening attachment data
+ * \param attachment_data_read function for reading attachment data
+ * \param attachment_data_close function for closing attachment data (optional, free() will be used if NULL)
+ * \param attachment_data_filedata_free function for cleaning up custom data in quickmail_destroy (optional, free() will be used if NULL)
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_body_custom (quickmail mailobj, const char* mimetype, char* data, quickmail_attachment_open_fn attachment_data_open, quickmail_attachment_read_fn attachment_data_read, quickmail_attachment_close_fn attachment_data_close, quickmail_attachment_free_filedata_fn attachment_data_filedata_free);
+
+/*! \brief remove body from quickmail object
+ * \param mailobj quickmail object
+ * \param mimetype MIME type (text/plain will be used if set to NULL)
+ * \return zero on success
+ */
+DLL_EXPORT_LIBQUICKMAIL int quickmail_remove_body (quickmail mailobj, const char* mimetype);
+
+/*! \brief list bodies by calling a callback function for each body
+ * \param mailobj quickmail object
+ * \param callback function to call for each attachment
+ * \param callbackdata custom data to pass to the callback function
+ * \sa quickmail_list_attachment_callback_fn
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_list_bodies (quickmail mailobj, quickmail_list_attachment_callback_fn callback, void* callbackdata);
+
+/*! \brief add a file attachment to a quickmail object
+ * \param mailobj quickmail object
+ * \param path path of file to attach
+ * \param mimetype MIME type of file to attach (application/octet-stream will be used if set to NULL)
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_attachment_file (quickmail mailobj, const char* path, const char* mimetype);
+
+/*! \brief add an attachment from memory to a quickmail object
+ * \param mailobj quickmail object
+ * \param filename name of file to attach (must not include full path)
+ * \param mimetype MIME type of file to attach (set to NULL for default binary file)
+ * \param data data content
+ * \param datalen size of data in bytes
+ * \param mustfree non-zero if data must be freed by quickmail_destroy
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_attachment_memory (quickmail mailobj, const char* filename, const char* mimetype, char* data, size_t datalen, int mustfree);
+
+/*! \brief add an attachment with custom read functions to a quickmail object
+ * \param mailobj quickmail object
+ * \param filename name of file to attach (must not include full path)
+ * \param mimetype MIME type of file to attach (set to NULL for default binary file)
+ * \param data custom data passed to attachment_data_open and attachment_data_filedata_free functions
+ * \param attachment_data_open function for opening attachment data
+ * \param attachment_data_read function for reading attachment data
+ * \param attachment_data_close function for closing attachment data (optional, free() will be used if NULL)
+ * \param attachment_data_filedata_free function for cleaning up custom data in quickmail_destroy (optional, free() will be used if NULL)
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_add_attachment_custom (quickmail mailobj, const char* filename, const char* mimetype, char* data, quickmail_attachment_open_fn attachment_data_open, quickmail_attachment_read_fn attachment_data_read, quickmail_attachment_close_fn attachment_data_close, quickmail_attachment_free_filedata_fn attachment_data_filedata_free);
+
+/*! \brief remove attachment from quickmail object
+ * \param mailobj quickmail object
+ * \param filename name of file to attach (must not include full path)
+ * \return zero on success
+ */
+DLL_EXPORT_LIBQUICKMAIL int quickmail_remove_attachment (quickmail mailobj, const char* filename);
+
+/*! \brief list attachments by calling a callback function for each attachment
+ * \param mailobj quickmail object
+ * \param callback function to call for each attachment
+ * \param callbackdata custom data to pass to the callback function
+ * \sa quickmail_list_attachment_callback_fn
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_list_attachments (quickmail mailobj, quickmail_list_attachment_callback_fn callback, void* callbackdata);
+
+/*! \brief set the debug logging destination of a quickmail object
+ * \param mailobj quickmail object
+ * \param filehandle file handle of logging destination (or NULL for no logging)
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_set_debug_log (quickmail mailobj, FILE* filehandle);
+
+/*! \brief save the generated e-mail to a file
+ * \param mailobj quickmail object
+ * \param filehandle file handle to write the e-mail contents to
+ */
+DLL_EXPORT_LIBQUICKMAIL void quickmail_fsave (quickmail mailobj, FILE* filehandle);
+
+/*! \brief read data the next data from the e-mail contents (can be used as CURLOPT_READFUNCTION callback function)
+ * \param buffer buffer to copy data to (bust be able to hold size * nmemb bytes)
+ * \param size record size
+ * \param nmemb number of records to copy to \p buffer
+ * \param mailobj quickmail object
+ * \return number of bytes copied to \p buffer or 0 if at end
+ */
+DLL_EXPORT_LIBQUICKMAIL size_t quickmail_get_data (void* buffer, size_t size, size_t nmemb, void* mailobj);
+
+/*! \brief send the e-mail via SMTP
+ * \param mailobj quickmail object
+ * \param smtpserver IP address or hostname of SMTP server
+ * \param smtpport SMTP port number (normally this is 25)
+ * \param username username to use for authentication (or NULL if not needed)
+ * \param password password to use for authentication (or NULL if not needed)
+ * \return NULL on success or error message on error
+ */
+DLL_EXPORT_LIBQUICKMAIL const char* quickmail_send (quickmail mailobj, const char* smtpserver, unsigned int smtpport, const char* username, const char* password);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__INCLUDED_QUICKMAIL_H
diff --git a/3rdParty/libquickmail/quickmailprog.c b/3rdParty/libquickmail/quickmailprog.c
new file mode 100644
index 0000000..f15f52f
--- /dev/null
+++ b/3rdParty/libquickmail/quickmailprog.c
@@ -0,0 +1,307 @@
+/*! \file quickmailprog.c
+ * \brief source file of quickmail(light) application
+ * \author Brecht Sanders
+ * \date 2012-2013
+ * \copyright GPL
+ */
+/*
+ This file is part of libquickmail.
+
+ libquickmail is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ libquickmail is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libquickmail. If not, see <http://www.gnu.org/licenses/>.
+*/
+/*! \page quickmail quickmail - send e-mail from the command line
+ \details Send e-mail from the command line.
+ Features:
+ - multiple To/Cc/Bcc recipients
+ - multiple attachments without size limitation
+ - specifying the MIME-type to use for the message body
+ \section SYNOPSIS synopsis
+ quickmail -h server [-p port] [-u username] [-w password] -f email [-t email] [-c email] [-b email] [-s subject] [-m mimetype] [-d body] [-a file] [-v] [-?]
+ \section OPTIONS options
+ \verbatim
+ -h server hostname or IP address of SMTP server
+ -p port TCP port to use for SMTP connection (default is 25)
+ -u username username to use for SMTP authentication
+ -w password password to use for SMTP authentication
+ -f email From e-mail address
+ -t email To e-mail address (multiple -t can be specified)
+ -c email Cc e-mail address (multiple -c can be specified)
+ -b email Bcc e-mail address (multiple -b can be specified)
+ -s subject Subject
+ -m mimetype MIME used for the body (must be specified before -d)
+ -d body Body, if not specified will be read from standard input
+ -a file file to attach (multiple -a can be specified)
+ -v verbose mode
+ -? show help
+ \endverbatim
+ */
+
+#include "quickmail.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#ifndef NOCURL
+#include <curl/curl.h>
+#endif
+
+void show_help()
+{
+ printf(
+ "Usage: quickmail {-h server | -o filename} [-p port] [-u username] [-w password] -f email [-t email] [-c email] [-b email] [-s subject] [-m mimetype] [-d body] [-a file] [-v]\n" \
+ "Parameters:\n" \
+ " -h server \thostname or IP address of SMTP server\n" \
+ " -o filename \tname of file to dump the mail content to (- for stdout)\n" \
+ " -p port \tTCP port to use for SMTP connection (default is 25)\n" \
+ " -u username \tusername to use for SMTP authentication\n" \
+ " -w password \tpassword to use for SMTP authentication\n" \
+ " -f email \tFrom e-mail address\n" \
+ " -t email \tTo e-mail address (multiple -t can be specified)\n" \
+ " -c email \tCc e-mail address (multiple -c can be specified)\n" \
+ " -b email \tBcc e-mail address (multiple -b can be specified)\n" \
+ " -s subject \tSubject\n" \
+ " -m mimetype \tMIME used for the body (must be specified before -d)\n" \
+ " -d body \tbody, if not specified will be read from standard input\n" \
+ " -a file \tfile to attach (multiple -a can be specified)\n" \
+ " -v \tverbose mode\n" \
+ " -? \tshow help\n" \
+ "\n"
+ );
+}
+
+size_t email_info_attachment_read_stdin (void* handle, void* buf, size_t len)
+{
+ return fread(buf, 1, len, stdin);
+}
+
+int main (int argc, char *argv[])
+{
+ //default values
+ FILE* output_file = NULL;
+ const char* smtp_server = NULL;
+ int smtp_port = 25;
+ const char* smtp_username = NULL;
+ const char* smtp_password = NULL;
+ const char* mime_type = NULL;
+ char* body = NULL;
+
+ //show version
+#ifdef NOCURL
+ printf("quickmail %s\n", quickmail_get_version());
+#else
+ {
+ curl_version_info_data* curlversion = curl_version_info(CURLVERSION_NOW);
+ printf("quickmail %s (with libcurl %s)\n", quickmail_get_version(), (curlversion ? curlversion->version : curl_version()));
+ }
+#endif
+ //initialize mail object
+ quickmail_initialize();
+ quickmail mailobj = quickmail_create(NULL, NULL);
+
+ //process command line parameters
+ {
+ int i = 0;
+ char* param;
+ int paramerror = 0;
+ unsigned recipient_count = 0;
+ while (!paramerror && ++i < argc) {
+ if (!argv[i][0] || (argv[i][0] != '/' && argv[i][0] != '-')) {
+ paramerror++;
+ break;
+ } else {
+ param = NULL;
+ switch (tolower(argv[i][1])) {
+ case '?' :
+ show_help();
+ return 0;
+ case 'o' :
+ if (argv[i][2])
+ param = argv[i] + 2;
+ else if (i + 1 < argc && argv[i + 1])
+ param = argv[++i];
+ if (!param || !*param || strcmp(param, "-") == 0)
+ output_file = stdout;
+ else
+ if ((output_file = fopen(param, "wb")) == NULL)
+ fprintf(stderr, "Error writing to file: %s\n", param);
+ break;
+ case 'h' :
+ if (argv[i][2])
+ param = argv[i] + 2;
+ else if (i + 1 < argc && argv[i + 1])
+ param = argv[++i];
+ if (!param)
+ paramerror++;
+ else
+ smtp_server = param;
+ break;
+ case 'p' :
+ if (argv[i][2])
+ param = argv[i] + 2;
+ else if (i + 1 < argc && argv[i + 1])
+ param = argv[++i];
+ if (!param)
+ paramerror++;
+ else
+ smtp_port = atoi(param);
+ break;
+ case 'u' :
+ if (argv[i][2])
+ param = argv[i] + 2;
+ else if (i + 1 < argc && argv[i + 1])
+ param = argv[++i];
+ if (!param)
+ paramerror++;
+ else
+ smtp_username = param;
+ break;
+ case 'w' :
+ if (argv[i][2])
+ param = argv[i] + 2;
+ else if (i + 1 < argc && argv[i + 1])
+ param = argv[++i];
+ if (!param)
+ paramerror++;
+ else
+ smtp_password = param;
+ break;
+ case 'f' :
+ if (argv[i][2])
+ param = argv[i] + 2;
+ else if (i + 1 < argc && argv[i + 1])
+ param = argv[++i];
+ if (!param)
+ paramerror++;
+ else
+ quickmail_set_from(mailobj, param);
+ break;
+ case 't' :
+ if (argv[i][2])
+ param = argv[i] + 2;
+ else if (i + 1 < argc && argv[i + 1])
+ param = argv[++i];
+ if (!param) {
+ paramerror++;
+ } else {
+ quickmail_add_to(mailobj, param);
+ recipient_count++;
+ }
+ break;
+ case 'c' :
+ if (argv[i][2])
+ param = argv[i] + 2;
+ else if (i + 1 < argc && argv[i + 1])
+ param = argv[++i];
+ if (!param) {
+ paramerror++;
+ } else {
+ quickmail_add_cc(mailobj, param);
+ recipient_count++;
+ }
+ break;
+ case 'b' :
+ if (argv[i][2])
+ param = argv[i] + 2;
+ else if (i + 1 < argc && argv[i + 1])
+ param = argv[++i];
+ if (!param) {
+ paramerror++;
+ } else {
+ quickmail_add_bcc(mailobj, param);
+ recipient_count++;
+ }
+ break;
+ case 's' :
+ if (argv[i][2])
+ param = argv[i] + 2;
+ else if (i + 1 < argc && argv[i + 1])
+ param = argv[++i];
+ if (!param)
+ paramerror++;
+ else
+ quickmail_set_subject(mailobj, param);
+ break;
+ case 'm' :
+ if (argv[i][2])
+ param = argv[i] + 2;
+ else if (i + 1 < argc && argv[i + 1])
+ param = argv[++i];
+ if (!param)
+ paramerror++;
+ else
+ mime_type = param;
+ break;
+ case 'd' :
+ if (argv[i][2])
+ param = argv[i] + 2;
+ else if (i + 1 < argc && argv[i + 1])
+ param = argv[++i];
+ if (!param)
+ paramerror++;
+ else if (strcmp(param, "-") != 0)
+ body = param;
+ break;
+ case 'a' :
+ if (argv[i][2])
+ param = argv[i] + 2;
+ else if (i + 1 < argc && argv[i + 1])
+ param = argv[++i];
+ if (!param)
+ paramerror++;
+ else
+ quickmail_add_attachment_file(mailobj, param, NULL);
+ break;
+ case 'v' :
+ quickmail_set_debug_log(mailobj, stdout);
+ break;
+ default :
+ paramerror++;
+ break;
+ }
+ }
+ }
+ if (paramerror || (!smtp_server && !output_file) || !quickmail_get_from(mailobj)) {
+ fprintf(stderr, "Invalid command line parameters\n");
+ show_help();
+ return 1;
+ }
+ if (recipient_count == 0) {
+ fprintf(stderr, "At least one recipient (To/Cc/Bcc) must be specified\n");
+ return 1;
+ }
+ }
+ //read body from standard input if not given
+ if (body) {
+ quickmail_add_body_memory(mailobj, mime_type, body, strlen(body), 0);
+ } else {
+ quickmail_add_body_custom(mailobj, mime_type, NULL, NULL, email_info_attachment_read_stdin, NULL, NULL);
+ }
+ mime_type = NULL;
+ //send e-mail
+ int status = 0;
+ if (smtp_server) {
+ const char* errmsg;
+ if ((errmsg = quickmail_send(mailobj, smtp_server, smtp_port, smtp_username, smtp_password)) != NULL) {
+ status = 1;
+ fprintf(stderr, "Error sending e-mail: %s\n", errmsg);
+ }
+ }
+ //write e-mail body
+ if (output_file) {
+ quickmail_fsave(mailobj, output_file);
+ }
+ //clean up
+ quickmail_destroy(mailobj);
+ return status;
+}
diff --git a/3rdParty/libquickmail/smtpsocket.c b/3rdParty/libquickmail/smtpsocket.c
new file mode 100644
index 0000000..4b21600
--- /dev/null
+++ b/3rdParty/libquickmail/smtpsocket.c
@@ -0,0 +1,235 @@
+/*
+ This file is part of libquickmail.
+
+ libquickmail is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ libquickmail is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libquickmail. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "smtpsocket.h"
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#if _MSC_VER
+#define va_copy(dst,src) ((dst) = (src))
+#endif
+
+////////////////////////////////////////////////////////////////////////
+
+#define DEBUG_ERROR(errmsg)
+static const char* ERRMSG_MEMORY_ALLOCATION_ERROR = "Memory allocation error";
+
+////////////////////////////////////////////////////////////////////////
+
+SOCKET socket_open (const char* smtpserver, unsigned int smtpport, char** errmsg)
+{
+ struct in_addr ipv4addr;
+ SOCKET sock;
+ struct sockaddr_in remote_sock_addr;
+ static const struct linger linger_option = {-1, 2}; //linger 2 seconds when disconnecting
+ //determine IPv4 address of SMTP server
+ ipv4addr.s_addr = inet_addr(smtpserver);
+ if (ipv4addr.s_addr == INADDR_NONE) {
+ struct hostent* addr;
+ if ((addr = gethostbyname(smtpserver)) != NULL && (addr->h_addrtype == AF_INET && addr->h_length >= 1 && ((struct in_addr*)addr->h_addr)->s_addr != 0))
+ memcpy(&ipv4addr, addr->h_addr, sizeof(ipv4addr));
+ }
+ if (ipv4addr.s_addr == INADDR_NONE) {
+ if (errmsg)
+ *errmsg = "Unable to resolve SMTP server host name";
+ return INVALID_SOCKET;
+ }
+ //create socket
+ sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (sock == INVALID_SOCKET) {
+ if (errmsg)
+ *errmsg = "Error creating socket for SMTP connection";
+ return INVALID_SOCKET;
+ }
+ //connect
+ remote_sock_addr.sin_family = AF_INET;
+ remote_sock_addr.sin_port = htons(smtpport);
+ remote_sock_addr.sin_addr.s_addr = ipv4addr.s_addr;
+ if (connect(sock, (struct sockaddr*)&remote_sock_addr, sizeof(remote_sock_addr)) != 0) {
+ if (errmsg)
+ *errmsg = "Error connecting to SMTP server";
+ socket_close(sock);
+ return INVALID_SOCKET;
+ }
+ //set linger option
+ setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char*)&linger_option, sizeof(linger_option));
+ return sock;
+}
+
+void socket_close (SOCKET sock)
+{
+#ifndef _WIN32
+ shutdown(sock, 2);
+#else
+ closesocket(sock);
+#endif
+}
+
+int socket_send (SOCKET sock, const char* buf, int len)
+{
+ int total_sent = 0;
+ int l = 0;
+ if (sock == 0 || !buf)
+ return 0;
+ if (len < 0)
+ len = strlen(buf);
+ while (len > 0 && (l = send(sock, buf, len, 0)) < len) {
+ if (l == SOCKET_ERROR || l > len)
+ return (total_sent > 0 ? total_sent : -1);
+ total_sent += l;
+ buf += l;
+ len -= l;
+ }
+ return total_sent + l;
+}
+
+int socket_data_waiting (SOCKET sock, int timeoutseconds)
+{
+ fd_set rfds;
+ struct timeval tv;
+ if (sock == 0)
+ return 0;
+ //make a set with only this socket
+ FD_ZERO(&rfds);
+ FD_SET(sock, &rfds);
+ //make a timeval with the supplied timeout
+ tv.tv_sec = timeoutseconds;
+ tv.tv_usec = 0;
+ //check the socket
+ return (select(1, &rfds, NULL, NULL, &tv) > 0);
+}
+
+char* socket_receive_smtp (SOCKET sock)
+{
+ char* buf = NULL;
+ int bufsize = READ_BUFFER_CHUNK_SIZE;
+ int pos = 0;
+ int linestart;
+ int n;
+ if ((buf = (char*)malloc(bufsize)) == NULL) {
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ return NULL;
+ }
+ do {
+ //insert line break if response is multiple lines
+ if (pos > 0) {
+ buf[pos++] = '\n';
+ if (pos >= bufsize) {
+ char* newbuf;
+ if ((newbuf = (char*)realloc(buf, bufsize + READ_BUFFER_CHUNK_SIZE)) == NULL) {
+ free(buf);
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ return NULL;
+ }
+ buf = newbuf;
+ bufsize += READ_BUFFER_CHUNK_SIZE;
+ }
+ }
+ //add each character read until it is a line break
+ linestart = pos;
+ while ((n = recv(sock, buf + pos, 1, 0)) == 1) {
+ //detect optional carriage return (CR)
+ if (buf[pos] == '\r')
+ if (recv(sock, buf + pos, 1, 0) < 1)
+ return NULL;
+ //detect line feed (LF)
+ if (buf[pos] == '\n')
+ break;
+ //enlarge buffer if necessary
+ if (++pos >= bufsize) {
+ char* newbuf;
+ if ((newbuf = (char*)realloc(buf, bufsize + READ_BUFFER_CHUNK_SIZE)) == NULL) {
+ free(buf);
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ return NULL;
+ }
+ buf = newbuf;
+ bufsize += READ_BUFFER_CHUNK_SIZE;
+ }
+ }
+ //exit on error (e.g. if connection is closed)
+ if (n < 1)
+ return NULL;
+ } while (!isdigit(buf[linestart]) || !isdigit(buf[linestart + 1]) || !isdigit(buf[linestart + 2]) || buf[linestart + 3] != ' ');
+ buf[pos] = 0;
+ return buf;
+}
+
+int socket_get_smtp_code (SOCKET sock, char** message)
+{
+ int code;
+ char* buf = socket_receive_smtp(sock);
+ if (!buf || strlen(buf) < 4 || (buf[3] != ' ' && buf[3] != '-')) {
+ free(buf);
+ return 999;
+ }
+ //get code
+ buf[3] = 0;
+ code = atoi(buf);
+ //get error message (if needed)
+ if (message /*&& code >= 400*/)
+ *message = strdup(buf + 4);
+ //clean up and return
+ free(buf);
+ return code;
+}
+
+int socket_smtp_command (SOCKET sock, FILE* debuglog, const char* template, ...)
+{
+ char* message;
+ int statuscode;
+ //send command (if one is supplied)
+ if (template) {
+ va_list ap;
+ va_list aq;
+ char* cmd;
+ int cmdlen;
+ va_start(ap, template);
+ //construct command to send
+ va_copy(aq, ap);
+ cmdlen = vsnprintf(NULL, 0, template, aq);
+ va_end(aq);
+ if ((cmd = (char*)malloc(cmdlen + 3)) == NULL) {
+ DEBUG_ERROR(ERRMSG_MEMORY_ALLOCATION_ERROR)
+ if (debuglog)
+ fprintf(debuglog, ERRMSG_MEMORY_ALLOCATION_ERROR);
+ va_end(ap);
+ return 999;
+ }
+ vsnprintf(cmd, cmdlen + 1, template, ap);
+ //log command to send
+ if (debuglog)
+ fprintf(debuglog, "SMTP> %s\n", cmd);
+ //append CR+LF
+ strcpy(cmd + cmdlen, "\r\n");
+ cmdlen += 2;
+ //send command
+ statuscode = socket_send(sock, cmd, cmdlen);
+ //clean up
+ free(cmd);
+ va_end(ap);
+ if (statuscode < 0)
+ return 999;
+ }
+ //receive result
+ message = NULL;
+ statuscode = socket_get_smtp_code(sock, &message);
+ if (debuglog)
+ fprintf(debuglog, "SMTP< %i %s\n", statuscode, (message ? message : ""));
+ free(message);
+ return statuscode;
+}
diff --git a/3rdParty/libquickmail/smtpsocket.h b/3rdParty/libquickmail/smtpsocket.h
new file mode 100644
index 0000000..8aed1e5
--- /dev/null
+++ b/3rdParty/libquickmail/smtpsocket.h
@@ -0,0 +1,107 @@
+/*! \file smtpsocket.h
+ * \brief header file for TCP/IP socket and SMTP communication functions
+ * \author Brecht Sanders
+ * \date 2012-2013
+ * \copyright GPL
+ */
+/*
+ This file is part of libquickmail.
+
+ libquickmail is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ libquickmail is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libquickmail. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __INCLUDED_SMTPSOCKET_H
+#define __INCLUDED_SMTPSOCKET_H
+
+#ifdef _WIN32
+#include <winsock2.h>
+#else
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#ifndef SOCKET
+#define SOCKET int
+#endif
+#ifndef INVALID_SOCKET
+#define INVALID_SOCKET -1
+#endif
+#ifndef SOCKET_ERROR
+#define SOCKET_ERROR -1
+#endif
+#endif
+#include <stdio.h>
+#include <stdarg.h>
+
+#define READ_BUFFER_CHUNK_SIZE 128
+#define WRITE_BUFFER_CHUNK_SIZE 128
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*! \brief connect network socket
+ * \param smtpserver hostname or IP address of server
+ * \param smtpport TCP port to connect to
+ * \param errmsg optional pointer to where error message will be stored (must not be freed by caller)
+ * \return open network socket or INVALID_SOCKET on error
+*/
+SOCKET socket_open (const char* smtpserver, unsigned int smtpport, char** errmsg);
+
+/*! \brief disconnect network socket
+ * \param sock open network socket
+*/
+void socket_close (SOCKET sock);
+
+/*! \brief send data to a network socket
+ * \param sock open network socket
+ * \param buf buffer containing data
+ * \param len size of buffer in bytes
+ * \return number of bytes sent
+*/
+int socket_send (SOCKET sock, const char* buf, int len);
+
+/*! \brief check if data is waiting to be read from network socket
+ * \param sock open network socket
+ * \param timeoutseconds number of seconds to wait (0 to return immediately)
+ * \return nonzero if data is waiting
+*/
+int socket_data_waiting (SOCKET sock, int timeoutseconds);
+
+/*! \brief read SMTP response from network socket
+ * \param sock open network socket
+ * \return null-terminated string containing received data (must be freed by caller), or NULL
+*/
+char* socket_receive_stmp (SOCKET sock);
+
+/*! \brief read SMTP response from network socket
+ * \param sock open network socket
+ * \param errmsg optional pointer to where error message will be stored (must be freed by caller)
+ * \return SMTP status code (code >= 400 means error)
+*/
+int socket_get_smtp_code (SOCKET sock, char** errmsg);
+
+/*! \brief send SMTP command and return status code
+ * \param sock open network socket
+ * \param debuglog file handle to write debugging information to (NULL for no debugging)
+ * \param template printf style formatting template
+ * \return SMTP status code (code >= 400 means error)
+*/
+int socket_smtp_command (SOCKET sock, FILE* debuglog, const char* template, ...);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__INCLUDED_SMTPSOCKET_H
diff --git a/3rdParty/sha1/Makefile b/3rdParty/sha1/Makefile
new file mode 100644
index 0000000..66aaf2b
--- /dev/null
+++ b/3rdParty/sha1/Makefile
@@ -0,0 +1,41 @@
+#
+# Makefile
+#
+# Copyright (C) 1998, 2009
+# Paul E. Jones <paulej@packetizer.com>
+# All Rights Reserved.
+#
+#############################################################################
+# $Id: Makefile 12 2009-06-22 19:34:25Z paulej $
+#############################################################################
+#
+# Description:
+# This is a makefile for UNIX to build the programs sha, shacmp, and
+# shatest
+#
+#
+
+CC = g++
+
+CFLAGS = -c -O2 -Wall -D_FILE_OFFSET_BITS=64
+
+LIBS =
+
+OBJS = sha1.o
+
+all: sha shacmp shatest
+
+sha: sha.o $(OBJS)
+ $(CC) -o $@ sha.o $(OBJS) $(LIBS)
+
+shacmp: shacmp.o $(OBJS)
+ $(CC) -o $@ shacmp.o $(OBJS) $(LIBS)
+
+shatest: shatest.o $(OBJS)
+ $(CC) -o $@ shatest.o $(OBJS) $(LIBS)
+
+%.o: %.cpp
+ $(CC) $(CFLAGS) -o $@ $<
+
+clean:
+ $(RM) *.o sha shacmp shatest
diff --git a/3rdParty/sha1/Makefile.nt b/3rdParty/sha1/Makefile.nt
new file mode 100644
index 0000000..9bacf64
--- /dev/null
+++ b/3rdParty/sha1/Makefile.nt
@@ -0,0 +1,48 @@
+#
+# Makefile.nt
+#
+# Copyright (C) 1998, 2009
+# Paul E. Jones <paulej@packetizer.com>
+# All Rights Reserved.
+#
+#############################################################################
+# $Id: Makefile.nt 13 2009-06-22 20:20:32Z paulej $
+#############################################################################
+#
+# Description:
+# This is a makefile for Win32 to build the programs sha, shacmp, and
+# shatest
+#
+# Portability Issues:
+# Designed to work with Visual C++
+#
+#
+
+.silent:
+
+!include <win32.mak>
+
+RM = del /q
+
+LIBS = $(conlibs) setargv.obj
+
+CFLAGS = -D _CRT_SECURE_NO_WARNINGS /EHsc /O2 /W3
+
+OBJS = sha1.obj
+
+all: sha.exe shacmp.exe shatest.exe
+
+sha.exe: sha.obj $(OBJS)
+ $(link) $(conflags) -out:$@ sha.obj $(OBJS) $(LIBS)
+
+shacmp.exe: shacmp.obj $(OBJS)
+ $(link) $(conflags) -out:$@ shacmp.obj $(OBJS) $(LIBS)
+
+shatest.exe: shatest.obj $(OBJS)
+ $(link) $(conflags) -out:$@ shatest.obj $(OBJS) $(LIBS)
+
+.cpp.obj:
+ $(cc) $(CFLAGS) $(cflags) $(cvars) $<
+
+clean:
+ $(RM) *.obj sha.exe shacmp.exe shatest.exe
diff --git a/3rdParty/sha1/license.txt b/3rdParty/sha1/license.txt
new file mode 100644
index 0000000..8d7f394
--- /dev/null
+++ b/3rdParty/sha1/license.txt
@@ -0,0 +1,14 @@
+Copyright (C) 1998, 2009
+Paul E. Jones <paulej@packetizer.com>
+
+Freeware Public License (FPL)
+
+This software is licensed as "freeware." Permission to distribute
+this software in source and binary forms, including incorporation
+into other products, is hereby granted without a fee. THIS SOFTWARE
+IS PROVIDED 'AS IS' AND WITHOUT ANY EXPRESSED OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHOR SHALL NOT BE HELD
+LIABLE FOR ANY DAMAGES RESULTING FROM THE USE OF THIS SOFTWARE, EITHER
+DIRECTLY OR INDIRECTLY, INCLUDING, BUT NOT LIMITED TO, LOSS OF DATA
+OR DATA BEING RENDERED INACCURATE.
diff --git a/3rdParty/sha1/sha.cpp b/3rdParty/sha1/sha.cpp
new file mode 100644
index 0000000..ad86086
--- /dev/null
+++ b/3rdParty/sha1/sha.cpp
@@ -0,0 +1,176 @@
+/*
+ * sha.cpp
+ *
+ * Copyright (C) 1998, 2009
+ * Paul E. Jones <paulej@packetizer.com>
+ * All Rights Reserved
+ *
+ *****************************************************************************
+ * $Id: sha.cpp 13 2009-06-22 20:20:32Z paulej $
+ *****************************************************************************
+ *
+ * Description:
+ * This utility will display the message digest (fingerprint) for
+ * the specified file(s).
+ *
+ * Portability Issues:
+ * None.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#ifdef WIN32
+#include <io.h>
+#endif
+#include <fcntl.h>
+#include "sha1.h"
+
+/*
+ * Function prototype
+ */
+void usage();
+
+
+/*
+ * main
+ *
+ * Description:
+ * This is the entry point for the program
+ *
+ * Parameters:
+ * argc: [in]
+ * This is the count of arguments in the argv array
+ * argv: [in]
+ * This is an array of filenames for which to compute message digests
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+int main(int argc, char *argv[])
+{
+ SHA1 sha; // SHA-1 class
+ FILE *fp; // File pointer for reading files
+ char c; // Character read from file
+ unsigned message_digest[5]; // Message digest from "sha"
+ int i; // Counter
+ bool reading_stdin; // Are we reading standard in?
+ bool read_stdin = false; // Have we read stdin?
+
+ /*
+ * Check the program arguments and print usage information if -?
+ * or --help is passed as the first argument.
+ */
+ if (argc > 1 && (!strcmp(argv[1],"-?") || !strcmp(argv[1],"--help")))
+ {
+ usage();
+ return 1;
+ }
+
+ /*
+ * For each filename passed in on the command line, calculate the
+ * SHA-1 value and display it.
+ */
+ for(i = 0; i < argc; i++)
+ {
+ /*
+ * We start the counter at 0 to guarantee entry into the for loop.
+ * So if 'i' is zero, we will increment it now. If there is no
+ * argv[1], we will use STDIN below.
+ */
+ if (i == 0)
+ {
+ i++;
+ }
+
+ if (argc == 1 || !strcmp(argv[i],"-"))
+ {
+#ifdef WIN32
+ _setmode(_fileno(stdin), _O_BINARY);
+#endif
+ fp = stdin;
+ reading_stdin = true;
+ }
+ else
+ {
+ if (!(fp = fopen(argv[i],"rb")))
+ {
+ fprintf(stderr, "sha: unable to open file %s\n", argv[i]);
+ return 2;
+ }
+ reading_stdin = false;
+ }
+
+ /*
+ * We do not want to read STDIN multiple times
+ */
+ if (reading_stdin)
+ {
+ if (read_stdin)
+ {
+ continue;
+ }
+
+ read_stdin = true;
+ }
+
+ /*
+ * Reset the SHA1 object and process input
+ */
+ sha.Reset();
+
+ c = fgetc(fp);
+ while(!feof(fp))
+ {
+ sha.Input(c);
+ c = fgetc(fp);
+ }
+
+ if (!reading_stdin)
+ {
+ fclose(fp);
+ }
+
+ if (!sha.Result(message_digest))
+ {
+ fprintf(stderr,"sha: could not compute message digest for %s\n",
+ reading_stdin?"STDIN":argv[i]);
+ }
+ else
+ {
+ printf( "%08X %08X %08X %08X %08X - %s\n",
+ message_digest[0],
+ message_digest[1],
+ message_digest[2],
+ message_digest[3],
+ message_digest[4],
+ reading_stdin?"STDIN":argv[i]);
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * usage
+ *
+ * Description:
+ * This function will display program usage information to the user.
+ *
+ * Parameters:
+ * None.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void usage()
+{
+ printf("usage: sha <file> [<file> ...]\n");
+ printf("\tThis program will display the message digest (fingerprint)\n");
+ printf("\tfor files using the Secure Hashing Algorithm (SHA-1).\n");
+}
diff --git a/3rdParty/sha1/sha1.cpp b/3rdParty/sha1/sha1.cpp
new file mode 100644
index 0000000..fdcbdcc
--- /dev/null
+++ b/3rdParty/sha1/sha1.cpp
@@ -0,0 +1,589 @@
+/*
+ * sha1.cpp
+ *
+ * Copyright (C) 1998, 2009
+ * Paul E. Jones <paulej@packetizer.com>
+ * All Rights Reserved.
+ *
+ *****************************************************************************
+ * $Id: sha1.cpp 12 2009-06-22 19:34:25Z paulej $
+ *****************************************************************************
+ *
+ * Description:
+ * This class implements the Secure Hashing Standard as defined
+ * in FIPS PUB 180-1 published April 17, 1995.
+ *
+ * The Secure Hashing Standard, which uses the Secure Hashing
+ * Algorithm (SHA), produces a 160-bit message digest for a
+ * given data stream. In theory, it is highly improbable that
+ * two messages will produce the same message digest. Therefore,
+ * this algorithm can serve as a means of providing a "fingerprint"
+ * for a message.
+ *
+ * Portability Issues:
+ * SHA-1 is defined in terms of 32-bit "words". This code was
+ * written with the expectation that the processor has at least
+ * a 32-bit machine word size. If the machine word size is larger,
+ * the code should still function properly. One caveat to that
+ * is that the input functions taking characters and character arrays
+ * assume that only 8 bits of information are stored in each character.
+ *
+ * Caveats:
+ * SHA-1 is designed to work with messages less than 2^64 bits long.
+ * Although SHA-1 allows a message digest to be generated for
+ * messages of any number of bits less than 2^64, this implementation
+ * only works with messages with a length that is a multiple of 8
+ * bits.
+ *
+ */
+
+
+#include "sha1.h"
+
+/*
+ * SHA1
+ *
+ * Description:
+ * This is the constructor for the sha1 class.
+ *
+ * Parameters:
+ * None.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+SHA1::SHA1()
+{
+ Reset();
+}
+
+/*
+ * ~SHA1
+ *
+ * Description:
+ * This is the destructor for the sha1 class
+ *
+ * Parameters:
+ * None.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+SHA1::~SHA1()
+{
+ // The destructor does nothing
+}
+
+/*
+ * Reset
+ *
+ * Description:
+ * This function will initialize the sha1 class member variables
+ * in preparation for computing a new message digest.
+ *
+ * Parameters:
+ * None.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void SHA1::Reset()
+{
+ Length_Low = 0;
+ Length_High = 0;
+ Message_Block_Index = 0;
+
+ H[0] = 0x67452301;
+ H[1] = 0xEFCDAB89;
+ H[2] = 0x98BADCFE;
+ H[3] = 0x10325476;
+ H[4] = 0xC3D2E1F0;
+
+ Computed = false;
+ Corrupted = false;
+}
+
+/*
+ * Result
+ *
+ * Description:
+ * This function will return the 160-bit message digest into the
+ * array provided.
+ *
+ * Parameters:
+ * message_digest_array: [out]
+ * This is an array of five unsigned integers which will be filled
+ * with the message digest that has been computed.
+ *
+ * Returns:
+ * True if successful, false if it failed.
+ *
+ * Comments:
+ *
+ */
+bool SHA1::Result(unsigned *message_digest_array)
+{
+ int i; // Counter
+
+ if (Corrupted)
+ {
+ return false;
+ }
+
+ if (!Computed)
+ {
+ PadMessage();
+ Computed = true;
+ }
+
+ for(i = 0; i < 5; i++)
+ {
+ message_digest_array[i] = H[i];
+ }
+
+ return true;
+}
+
+/*
+ * Input
+ *
+ * Description:
+ * This function accepts an array of octets as the next portion of
+ * the message.
+ *
+ * Parameters:
+ * message_array: [in]
+ * An array of characters representing the next portion of the
+ * message.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void SHA1::Input( const unsigned char *message_array,
+ unsigned length)
+{
+ if (!length)
+ {
+ return;
+ }
+
+ if (Computed || Corrupted)
+ {
+ Corrupted = true;
+ return;
+ }
+
+ while(length-- && !Corrupted)
+ {
+ Message_Block[Message_Block_Index++] = (*message_array & 0xFF);
+
+ Length_Low += 8;
+ Length_Low &= 0xFFFFFFFF; // Force it to 32 bits
+ if (Length_Low == 0)
+ {
+ Length_High++;
+ Length_High &= 0xFFFFFFFF; // Force it to 32 bits
+ if (Length_High == 0)
+ {
+ Corrupted = true; // Message is too long
+ }
+ }
+
+ if (Message_Block_Index == 64)
+ {
+ ProcessMessageBlock();
+ }
+
+ message_array++;
+ }
+}
+
+/*
+ * Input
+ *
+ * Description:
+ * This function accepts an array of octets as the next portion of
+ * the message.
+ *
+ * Parameters:
+ * message_array: [in]
+ * An array of characters representing the next portion of the
+ * message.
+ * length: [in]
+ * The length of the message_array
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void SHA1::Input( const char *message_array,
+ unsigned length)
+{
+ Input((unsigned char *) message_array, length);
+}
+
+/*
+ * Input
+ *
+ * Description:
+ * This function accepts a single octets as the next message element.
+ *
+ * Parameters:
+ * message_element: [in]
+ * The next octet in the message.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void SHA1::Input(unsigned char message_element)
+{
+ Input(&message_element, 1);
+}
+
+/*
+ * Input
+ *
+ * Description:
+ * This function accepts a single octet as the next message element.
+ *
+ * Parameters:
+ * message_element: [in]
+ * The next octet in the message.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void SHA1::Input(char message_element)
+{
+ Input((unsigned char *) &message_element, 1);
+}
+
+/*
+ * operator<<
+ *
+ * Description:
+ * This operator makes it convenient to provide character strings to
+ * the SHA1 object for processing.
+ *
+ * Parameters:
+ * message_array: [in]
+ * The character array to take as input.
+ *
+ * Returns:
+ * A reference to the SHA1 object.
+ *
+ * Comments:
+ * Each character is assumed to hold 8 bits of information.
+ *
+ */
+SHA1& SHA1::operator<<(const char *message_array)
+{
+ const char *p = message_array;
+
+ while(*p)
+ {
+ Input(*p);
+ p++;
+ }
+
+ return *this;
+}
+
+/*
+ * operator<<
+ *
+ * Description:
+ * This operator makes it convenient to provide character strings to
+ * the SHA1 object for processing.
+ *
+ * Parameters:
+ * message_array: [in]
+ * The character array to take as input.
+ *
+ * Returns:
+ * A reference to the SHA1 object.
+ *
+ * Comments:
+ * Each character is assumed to hold 8 bits of information.
+ *
+ */
+SHA1& SHA1::operator<<(const unsigned char *message_array)
+{
+ const unsigned char *p = message_array;
+
+ while(*p)
+ {
+ Input(*p);
+ p++;
+ }
+
+ return *this;
+}
+
+/*
+ * operator<<
+ *
+ * Description:
+ * This function provides the next octet in the message.
+ *
+ * Parameters:
+ * message_element: [in]
+ * The next octet in the message
+ *
+ * Returns:
+ * A reference to the SHA1 object.
+ *
+ * Comments:
+ * The character is assumed to hold 8 bits of information.
+ *
+ */
+SHA1& SHA1::operator<<(const char message_element)
+{
+ Input((unsigned char *) &message_element, 1);
+
+ return *this;
+}
+
+/*
+ * operator<<
+ *
+ * Description:
+ * This function provides the next octet in the message.
+ *
+ * Parameters:
+ * message_element: [in]
+ * The next octet in the message
+ *
+ * Returns:
+ * A reference to the SHA1 object.
+ *
+ * Comments:
+ * The character is assumed to hold 8 bits of information.
+ *
+ */
+SHA1& SHA1::operator<<(const unsigned char message_element)
+{
+ Input(&message_element, 1);
+
+ return *this;
+}
+
+/*
+ * ProcessMessageBlock
+ *
+ * Description:
+ * This function will process the next 512 bits of the message
+ * stored in the Message_Block array.
+ *
+ * Parameters:
+ * None.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ * Many of the variable names in this function, especially the single
+ * character names, were used because those were the names used
+ * in the publication.
+ *
+ */
+void SHA1::ProcessMessageBlock()
+{
+ const unsigned K[] = { // Constants defined for SHA-1
+ 0x5A827999,
+ 0x6ED9EBA1,
+ 0x8F1BBCDC,
+ 0xCA62C1D6
+ };
+ int t; // Loop counter
+ unsigned temp; // Temporary word value
+ unsigned W[80]; // Word sequence
+ unsigned A, B, C, D, E; // Word buffers
+
+ /*
+ * Initialize the first 16 words in the array W
+ */
+ for(t = 0; t < 16; t++)
+ {
+ W[t] = ((unsigned) Message_Block[t * 4]) << 24;
+ W[t] |= ((unsigned) Message_Block[t * 4 + 1]) << 16;
+ W[t] |= ((unsigned) Message_Block[t * 4 + 2]) << 8;
+ W[t] |= ((unsigned) Message_Block[t * 4 + 3]);
+ }
+
+ for(t = 16; t < 80; t++)
+ {
+ W[t] = CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]);
+ }
+
+ A = H[0];
+ B = H[1];
+ C = H[2];
+ D = H[3];
+ E = H[4];
+
+ for(t = 0; t < 20; t++)
+ {
+ temp = CircularShift(5,A) + ((B & C) | ((~B) & D)) + E + W[t] + K[0];
+ temp &= 0xFFFFFFFF;
+ E = D;
+ D = C;
+ C = CircularShift(30,B);
+ B = A;
+ A = temp;
+ }
+
+ for(t = 20; t < 40; t++)
+ {
+ temp = CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1];
+ temp &= 0xFFFFFFFF;
+ E = D;
+ D = C;
+ C = CircularShift(30,B);
+ B = A;
+ A = temp;
+ }
+
+ for(t = 40; t < 60; t++)
+ {
+ temp = CircularShift(5,A) +
+ ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2];
+ temp &= 0xFFFFFFFF;
+ E = D;
+ D = C;
+ C = CircularShift(30,B);
+ B = A;
+ A = temp;
+ }
+
+ for(t = 60; t < 80; t++)
+ {
+ temp = CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3];
+ temp &= 0xFFFFFFFF;
+ E = D;
+ D = C;
+ C = CircularShift(30,B);
+ B = A;
+ A = temp;
+ }
+
+ H[0] = (H[0] + A) & 0xFFFFFFFF;
+ H[1] = (H[1] + B) & 0xFFFFFFFF;
+ H[2] = (H[2] + C) & 0xFFFFFFFF;
+ H[3] = (H[3] + D) & 0xFFFFFFFF;
+ H[4] = (H[4] + E) & 0xFFFFFFFF;
+
+ Message_Block_Index = 0;
+}
+
+/*
+ * PadMessage
+ *
+ * Description:
+ * According to the standard, the message must be padded to an even
+ * 512 bits. The first padding bit must be a '1'. The last 64 bits
+ * represent the length of the original message. All bits in between
+ * should be 0. This function will pad the message according to those
+ * rules by filling the message_block array accordingly. It will also
+ * call ProcessMessageBlock() appropriately. When it returns, it
+ * can be assumed that the message digest has been computed.
+ *
+ * Parameters:
+ * None.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void SHA1::PadMessage()
+{
+ /*
+ * Check to see if the current message block is too small to hold
+ * the initial padding bits and length. If so, we will pad the
+ * block, process it, and then continue padding into a second block.
+ */
+ if (Message_Block_Index > 55)
+ {
+ Message_Block[Message_Block_Index++] = 0x80;
+ while(Message_Block_Index < 64)
+ {
+ Message_Block[Message_Block_Index++] = 0;
+ }
+
+ ProcessMessageBlock();
+
+ while(Message_Block_Index < 56)
+ {
+ Message_Block[Message_Block_Index++] = 0;
+ }
+ }
+ else
+ {
+ Message_Block[Message_Block_Index++] = 0x80;
+ while(Message_Block_Index < 56)
+ {
+ Message_Block[Message_Block_Index++] = 0;
+ }
+
+ }
+
+ /*
+ * Store the message length as the last 8 octets
+ */
+ Message_Block[56] = (Length_High >> 24) & 0xFF;
+ Message_Block[57] = (Length_High >> 16) & 0xFF;
+ Message_Block[58] = (Length_High >> 8) & 0xFF;
+ Message_Block[59] = (Length_High) & 0xFF;
+ Message_Block[60] = (Length_Low >> 24) & 0xFF;
+ Message_Block[61] = (Length_Low >> 16) & 0xFF;
+ Message_Block[62] = (Length_Low >> 8) & 0xFF;
+ Message_Block[63] = (Length_Low) & 0xFF;
+
+ ProcessMessageBlock();
+}
+
+
+/*
+ * CircularShift
+ *
+ * Description:
+ * This member function will perform a circular shifting operation.
+ *
+ * Parameters:
+ * bits: [in]
+ * The number of bits to shift (1-31)
+ * word: [in]
+ * The value to shift (assumes a 32-bit integer)
+ *
+ * Returns:
+ * The shifted value.
+ *
+ * Comments:
+ *
+ */
+unsigned SHA1::CircularShift(int bits, unsigned word)
+{
+ return ((word << bits) & 0xFFFFFFFF) | ((word & 0xFFFFFFFF) >> (32-bits));
+}
diff --git a/3rdParty/sha1/sha1.h b/3rdParty/sha1/sha1.h
new file mode 100644
index 0000000..c0efa1c
--- /dev/null
+++ b/3rdParty/sha1/sha1.h
@@ -0,0 +1,89 @@
+/*
+ * sha1.h
+ *
+ * Copyright (C) 1998, 2009
+ * Paul E. Jones <paulej@packetizer.com>
+ * All Rights Reserved.
+ *
+ *****************************************************************************
+ * $Id: sha1.h 12 2009-06-22 19:34:25Z paulej $
+ *****************************************************************************
+ *
+ * Description:
+ * This class implements the Secure Hashing Standard as defined
+ * in FIPS PUB 180-1 published April 17, 1995.
+ *
+ * Many of the variable names in this class, especially the single
+ * character names, were used because those were the names used
+ * in the publication.
+ *
+ * Please read the file sha1.cpp for more information.
+ *
+ */
+
+#ifndef _SHA1_H_
+#define _SHA1_H_
+
+class SHA1
+{
+
+ public:
+
+ SHA1();
+ virtual ~SHA1();
+
+ /*
+ * Re-initialize the class
+ */
+ void Reset();
+
+ /*
+ * Returns the message digest
+ */
+ bool Result(unsigned *message_digest_array);
+
+ /*
+ * Provide input to SHA1
+ */
+ void Input( const unsigned char *message_array,
+ unsigned length);
+ void Input( const char *message_array,
+ unsigned length);
+ void Input(unsigned char message_element);
+ void Input(char message_element);
+ SHA1& operator<<(const char *message_array);
+ SHA1& operator<<(const unsigned char *message_array);
+ SHA1& operator<<(const char message_element);
+ SHA1& operator<<(const unsigned char message_element);
+
+ private:
+
+ /*
+ * Process the next 512 bits of the message
+ */
+ void ProcessMessageBlock();
+
+ /*
+ * Pads the current message block to 512 bits
+ */
+ void PadMessage();
+
+ /*
+ * Performs a circular left shift operation
+ */
+ inline unsigned CircularShift(int bits, unsigned word);
+
+ unsigned H[5]; // Message digest buffers
+
+ unsigned Length_Low; // Message length in bits
+ unsigned Length_High; // Message length in bits
+
+ unsigned char Message_Block[64]; // 512-bit message blocks
+ int Message_Block_Index; // Index into message block array
+
+ bool Computed; // Is the digest computed?
+ bool Corrupted; // Is the message digest corruped?
+
+};
+
+#endif
diff --git a/3rdParty/sha1/shacmp.cpp b/3rdParty/sha1/shacmp.cpp
new file mode 100644
index 0000000..476ad3f
--- /dev/null
+++ b/3rdParty/sha1/shacmp.cpp
@@ -0,0 +1,169 @@
+/*
+ * shacmp.cpp
+ *
+ * Copyright (C) 1998, 2009
+ * Paul E. Jones <paulej@packetizer.com>
+ * All Rights Reserved
+ *
+ *****************************************************************************
+ * $Id: shacmp.cpp 12 2009-06-22 19:34:25Z paulej $
+ *****************************************************************************
+ *
+ * Description:
+ * This utility will compare two files by producing a message digest
+ * for each file using the Secure Hashing Algorithm and comparing
+ * the message digests. This function will return 0 if they
+ * compare or 1 if they do not or if there is an error.
+ * Errors result in a return code higher than 1.
+ *
+ * Portability Issues:
+ * none.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include "sha1.h"
+
+/*
+ * Return codes
+ */
+#define SHA1_COMPARE 0
+#define SHA1_NO_COMPARE 1
+#define SHA1_USAGE_ERROR 2
+#define SHA1_FILE_ERROR 3
+
+/*
+ * Function prototype
+ */
+void usage();
+
+/*
+ * main
+ *
+ * Description:
+ * This is the entry point for the program
+ *
+ * Parameters:
+ * argc: [in]
+ * This is the count of arguments in the argv array
+ * argv: [in]
+ * This is an array of filenames for which to compute message digests
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+int main(int argc, char *argv[])
+{
+ SHA1 sha; // SHA-1 class
+ FILE *fp; // File pointer for reading files
+ char c; // Character read from file
+ unsigned message_digest[2][5]; // Message digest for files
+ int i; // Counter
+ bool message_match; // Message digest match flag
+ int returncode;
+
+ /*
+ * If we have two arguments, we will assume they are filenames. If
+ * we do not have to arguments, call usage() and exit.
+ */
+ if (argc != 3)
+ {
+ usage();
+ return SHA1_USAGE_ERROR;
+ }
+
+ /*
+ * Get the message digests for each file
+ */
+ for(i = 1; i <= 2; i++)
+ {
+ sha.Reset();
+
+ if (!(fp = fopen(argv[i],"rb")))
+ {
+ fprintf(stderr, "sha: unable to open file %s\n", argv[i]);
+ return SHA1_FILE_ERROR;
+ }
+
+ c = fgetc(fp);
+ while(!feof(fp))
+ {
+ sha.Input(c);
+ c = fgetc(fp);
+ }
+
+ fclose(fp);
+
+ if (!sha.Result(message_digest[i-1]))
+ {
+ fprintf(stderr,"shacmp: could not compute message digest for %s\n",
+ argv[i]);
+ return SHA1_FILE_ERROR;
+ }
+ }
+
+ /*
+ * Compare the message digest values
+ */
+ message_match = true;
+ for(i = 0; i < 5; i++)
+ {
+ if (message_digest[0][i] != message_digest[1][i])
+ {
+ message_match = false;
+ break;
+ }
+ }
+
+ if (message_match)
+ {
+ printf("Fingerprints match:\n");
+ returncode = SHA1_COMPARE;
+ }
+ else
+ {
+ printf("Fingerprints do not match:\n");
+ returncode = SHA1_NO_COMPARE;
+ }
+
+ printf( "\t%08X %08X %08X %08X %08X\n",
+ message_digest[0][0],
+ message_digest[0][1],
+ message_digest[0][2],
+ message_digest[0][3],
+ message_digest[0][4]);
+ printf( "\t%08X %08X %08X %08X %08X\n",
+ message_digest[1][0],
+ message_digest[1][1],
+ message_digest[1][2],
+ message_digest[1][3],
+ message_digest[1][4]);
+
+ return returncode;
+}
+
+/*
+ * usage
+ *
+ * Description:
+ * This function will display program usage information to the user.
+ *
+ * Parameters:
+ * None.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void usage()
+{
+ printf("usage: shacmp <file> <file>\n");
+ printf("\tThis program will compare the message digests (fingerprints)\n");
+ printf("\tfor two files using the Secure Hashing Algorithm (SHA-1).\n");
+}
diff --git a/3rdParty/sha1/shatest.cpp b/3rdParty/sha1/shatest.cpp
new file mode 100644
index 0000000..4d29ef9
--- /dev/null
+++ b/3rdParty/sha1/shatest.cpp
@@ -0,0 +1,149 @@
+/*
+ * shatest.cpp
+ *
+ * Copyright (C) 1998, 2009
+ * Paul E. Jones <paulej@packetizer.com>
+ * All Rights Reserved
+ *
+ *****************************************************************************
+ * $Id: shatest.cpp 12 2009-06-22 19:34:25Z paulej $
+ *****************************************************************************
+ *
+ * Description:
+ * This file will exercise the SHA1 class and perform the three
+ * tests documented in FIPS PUB 180-1.
+ *
+ * Portability Issues:
+ * None.
+ *
+ */
+
+#include <iostream>
+#include "sha1.h"
+
+using namespace std;
+
+/*
+ * Define patterns for testing
+ */
+#define TESTA "abc"
+#define TESTB "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+
+/*
+ * Function prototype
+ */
+void DisplayMessageDigest(unsigned *message_digest);
+
+/*
+ * main
+ *
+ * Description:
+ * This is the entry point for the program
+ *
+ * Parameters:
+ * None.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+int main()
+{
+ SHA1 sha;
+ unsigned message_digest[5];
+
+ /*
+ * Perform test A
+ */
+ cout << endl << "Test A: 'abc'" << endl;
+
+ sha.Reset();
+ sha << TESTA;
+
+ if (!sha.Result(message_digest))
+ {
+ cerr << "ERROR-- could not compute message digest" << endl;
+ }
+ else
+ {
+ DisplayMessageDigest(message_digest);
+ cout << "Should match:" << endl;
+ cout << '\t' << "A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D" << endl;
+ }
+
+ /*
+ * Perform test B
+ */
+ cout << endl << "Test B: " << TESTB << endl;
+
+ sha.Reset();
+ sha << TESTB;
+
+ if (!sha.Result(message_digest))
+ {
+ cerr << "ERROR-- could not compute message digest" << endl;
+ }
+ else
+ {
+ DisplayMessageDigest(message_digest);
+ cout << "Should match:" << endl;
+ cout << '\t' << "84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1" << endl;
+ }
+
+ /*
+ * Perform test C
+ */
+ cout << endl << "Test C: One million 'a' characters" << endl;
+
+ sha.Reset();
+ for(int i = 1; i <= 1000000; i++) sha.Input('a');
+
+ if (!sha.Result(message_digest))
+ {
+ cerr << "ERROR-- could not compute message digest" << endl;
+ }
+ else
+ {
+ DisplayMessageDigest(message_digest);
+ cout << "Should match:" << endl;
+ cout << '\t' << "34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F" << endl;
+ }
+
+ return 0;
+}
+
+/*
+ * DisplayMessageDigest
+ *
+ * Description:
+ * Display Message Digest array
+ *
+ * Parameters:
+ * None.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void DisplayMessageDigest(unsigned *message_digest)
+{
+ ios::fmtflags flags;
+
+ cout << '\t';
+
+ flags = cout.setf(ios::hex|ios::uppercase,ios::basefield);
+ cout.setf(ios::uppercase);
+
+ for(int i = 0; i < 5 ; i++)
+ {
+ cout << message_digest[i] << ' ';
+ }
+
+ cout << endl;
+
+ cout.setf(flags);
+}
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e6cc8f6..16ae05f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,6 +20,7 @@ include_directories(${BOOSTER_INC})
include_directories(${CPPDB_INC})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/libb64/include)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/libquickmail)
find_program(TMPLCC cppcms_tmpl_cc)
find_program(XGETTEXT xgettext)
@@ -45,7 +46,9 @@ set(SRC
src/master.cpp
src/intro.cpp
src/captcha.cpp
+ src/mail.cpp
src/user.cpp
+ src/sha1.cpp
)
add_custom_command(
@@ -67,7 +70,8 @@ endif()
link_directories( "${PROJECT_SOURCE_DIR}/3rdParty/captcha" )
link_directories( "${PROJECT_SOURCE_DIR}/3rdParty/libb64" )
-target_link_libraries(strusCms ${BOOSTER} ${CPPCMS} ${CPPDB} captcha b64)
+link_directories( "${PROJECT_SOURCE_DIR}/3rdParty/libquickmail" )
+target_link_libraries(strusCms ${BOOSTER} ${CPPCMS} ${CPPDB} captcha b64 quickmail curl)
#~ set(LOCALES de fr)
#~
diff --git a/TODOS b/TODOS
new file mode 100644
index 0000000..699fcde
--- /dev/null
+++ b/TODOS
@@ -0,0 +1,3 @@
+- hash the password, with salt (currently it's plain text which is a no go!)
+- check timeout when verifying the registration code of a user
+
diff --git a/config.js b/config.js
index 7cb125b..b161536 100644
--- a/config.js
+++ b/config.js
@@ -3,6 +3,13 @@
"script" : "/strusCms",
"media" : "/media",
"db_connection" : "sqlite3:db=./storage/db/strusCms.db;@pool_size=16",
+ "mail" : {
+ "server" : "smtp.andreasbaumann.cc",
+ "port" : 25,
+ "username" : "struscms",
+ "password" : "xx",
+ "from" : "no-reply@andreasbaumann.cc"
+ }
},
"service" : {
diff --git a/sql/sqlite3.sql b/sql/sqlite3.sql
index beefe6e..97ffcea 100644
--- a/sql/sqlite3.sql
+++ b/sql/sqlite3.sql
@@ -1,16 +1,33 @@
+PRAGMA foreign_keys = ON;
+
drop table if exists login;
drop table if exists user;
+drop table if exists userstatus;
+
+create table userstatus(
+ status char(1) primary key not null,
+ description varchar(32) not null
+);
+
+insert into userstatus values( 'U', 'User unknown' );
+insert into userstatus values( 'R', 'Currently in registration' );
+insert into userstatus values( 'A', 'Registration ok, user active' );
+insert into userstatus values( 'D', 'User disabled' );
create table user(
id integer primary key autoincrement not null,
username varchar(32) unique not null,
- password varchar(32) not null
+ password varchar(32) not null,
+ email varchar(32),
+ status char(1) references userstatus(status) default 'U',
+ registration_start timestamp,
+ code varchar(32)
);
-insert into user(username, password) values('admin','admin');
+insert into user(username, password, status) values('admin','admin', 'A');
create table login(
id integer primary key autoincrement not null,
user_id integer references user(id),
- last_login TIMESTAMP
+ last_login timestamp
);
diff --git a/src/mail.cpp b/src/mail.cpp
new file mode 100644
index 0000000..0c868d2
--- /dev/null
+++ b/src/mail.cpp
@@ -0,0 +1,53 @@
+#include "mail.hpp"
+
+#include <iostream>
+
+mailer::mailer( std::string server, unsigned short port, std::string username, std::string password, std::string from )
+ : server( server ), port( port ), username( username ), password( password ), from( from )
+{
+ quickmail_initialize( );
+ mailobj = quickmail_create( NULL, NULL );
+}
+
+mailer::~mailer( )
+{
+ quickmail_destroy( mailobj );
+}
+
+void mailer::send( )
+{
+ if( !from.empty( ) ) {
+ quickmail_set_from( mailobj, from.c_str( ) );
+ }
+
+ if( !to.empty( ) ) {
+ quickmail_add_to( mailobj, to.c_str( ) );
+ }
+
+ if( !subject.empty( ) ) {
+ quickmail_set_subject( mailobj, subject.c_str( ) );
+ }
+
+ if( !body.empty( ) ) {
+ quickmail_add_body_memory( mailobj, "text/plain", const_cast<char *>( body.c_str( ) ), body.size( ), 0 );
+ }
+
+ _hasError = false;
+ const char *errmsg;
+ errmsg = quickmail_send( mailobj, server.c_str( ), port, username.c_str( ), password.c_str( ) );
+ if( errmsg != NULL ) {
+ _hasError = true;
+ lastErrorMsg = std::string( errmsg );
+ }
+}
+
+bool mailer::hasError( )
+{
+ return _hasError;
+}
+
+std::string mailer::getLastError( )
+{
+ return lastErrorMsg;
+}
+
diff --git a/src/mail.hpp b/src/mail.hpp
new file mode 100644
index 0000000..3445d76
--- /dev/null
+++ b/src/mail.hpp
@@ -0,0 +1,33 @@
+#ifndef MAIL_HPP
+#define MAIL_HPP
+
+#include <string>
+
+#include "quickmail.h"
+
+class mailer {
+ private:
+ std::string server;
+ unsigned short port;
+ std::string username;
+ std::string password;
+ std::string from;
+ quickmail mailobj;
+ bool _hasError;
+ std::string lastErrorMsg;
+
+ public:
+ std::string to;
+ std::string subject;
+ std::string body;
+
+ public:
+ mailer( std::string server, unsigned short port, std::string username, std::string password, std::string from );
+ ~mailer( );
+ void send( );
+ bool hasError( );
+ std::string getLastError( );
+};
+
+
+#endif
diff --git a/src/sha1.cpp b/src/sha1.cpp
new file mode 100644
index 0000000..7fe99e0
--- /dev/null
+++ b/src/sha1.cpp
@@ -0,0 +1,593 @@
+/*
+ * sha1.cpp
+ *
+ * Copyright (C) 1998, 2009
+ * Paul E. Jones <paulej@packetizer.com>
+ * All Rights Reserved.
+ *
+ *****************************************************************************
+ * $Id: sha1.cpp 12 2009-06-22 19:34:25Z paulej $
+ *****************************************************************************
+ *
+ * Description:
+ * This class implements the Secure Hashing Standard as defined
+ * in FIPS PUB 180-1 published April 17, 1995.
+ *
+ * The Secure Hashing Standard, which uses the Secure Hashing
+ * Algorithm (SHA), produces a 160-bit message digest for a
+ * given data stream. In theory, it is highly improbable that
+ * two messages will produce the same message digest. Therefore,
+ * this algorithm can serve as a means of providing a "fingerprint"
+ * for a message.
+ *
+ * Portability Issues:
+ * SHA-1 is defined in terms of 32-bit "words". This code was
+ * written with the expectation that the processor has at least
+ * a 32-bit machine word size. If the machine word size is larger,
+ * the code should still function properly. One caveat to that
+ * is that the input functions taking characters and character arrays
+ * assume that only 8 bits of information are stored in each character.
+ *
+ * Caveats:
+ * SHA-1 is designed to work with messages less than 2^64 bits long.
+ * Although SHA-1 allows a message digest to be generated for
+ * messages of any number of bits less than 2^64, this implementation
+ * only works with messages with a length that is a multiple of 8
+ * bits.
+ *
+ */
+
+
+#include "sha1.hpp"
+
+namespace sha {
+
+/*
+ * SHA1
+ *
+ * Description:
+ * This is the constructor for the sha1 class.
+ *
+ * Parameters:
+ * None.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+SHA1::SHA1()
+{
+ Reset();
+}
+
+/*
+ * ~SHA1
+ *
+ * Description:
+ * This is the destructor for the sha1 class
+ *
+ * Parameters:
+ * None.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+SHA1::~SHA1()
+{
+ // The destructor does nothing
+}
+
+/*
+ * Reset
+ *
+ * Description:
+ * This function will initialize the sha1 class member variables
+ * in preparation for computing a new message digest.
+ *
+ * Parameters:
+ * None.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void SHA1::Reset()
+{
+ Length_Low = 0;
+ Length_High = 0;
+ Message_Block_Index = 0;
+
+ H[0] = 0x67452301;
+ H[1] = 0xEFCDAB89;
+ H[2] = 0x98BADCFE;
+ H[3] = 0x10325476;
+ H[4] = 0xC3D2E1F0;
+
+ Computed = false;
+ Corrupted = false;
+}
+
+/*
+ * Result
+ *
+ * Description:
+ * This function will return the 160-bit message digest into the
+ * array provided.
+ *
+ * Parameters:
+ * message_digest_array: [out]
+ * This is an array of five unsigned integers which will be filled
+ * with the message digest that has been computed.
+ *
+ * Returns:
+ * True if successful, false if it failed.
+ *
+ * Comments:
+ *
+ */
+bool SHA1::Result(unsigned *message_digest_array)
+{
+ int i; // Counter
+
+ if (Corrupted)
+ {
+ return false;
+ }
+
+ if (!Computed)
+ {
+ PadMessage();
+ Computed = true;
+ }
+
+ for(i = 0; i < 5; i++)
+ {
+ message_digest_array[i] = H[i];
+ }
+
+ return true;
+}
+
+/*
+ * Input
+ *
+ * Description:
+ * This function accepts an array of octets as the next portion of
+ * the message.
+ *
+ * Parameters:
+ * message_array: [in]
+ * An array of characters representing the next portion of the
+ * message.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void SHA1::Input( const unsigned char *message_array,
+ unsigned length)
+{
+ if (!length)
+ {
+ return;
+ }
+
+ if (Computed || Corrupted)
+ {
+ Corrupted = true;
+ return;
+ }
+
+ while(length-- && !Corrupted)
+ {
+ Message_Block[Message_Block_Index++] = (*message_array & 0xFF);
+
+ Length_Low += 8;
+ Length_Low &= 0xFFFFFFFF; // Force it to 32 bits
+ if (Length_Low == 0)
+ {
+ Length_High++;
+ Length_High &= 0xFFFFFFFF; // Force it to 32 bits
+ if (Length_High == 0)
+ {
+ Corrupted = true; // Message is too long
+ }
+ }
+
+ if (Message_Block_Index == 64)
+ {
+ ProcessMessageBlock();
+ }
+
+ message_array++;
+ }
+}
+
+/*
+ * Input
+ *
+ * Description:
+ * This function accepts an array of octets as the next portion of
+ * the message.
+ *
+ * Parameters:
+ * message_array: [in]
+ * An array of characters representing the next portion of the
+ * message.
+ * length: [in]
+ * The length of the message_array
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void SHA1::Input( const char *message_array,
+ unsigned length)
+{
+ Input((unsigned char *) message_array, length);
+}
+
+/*
+ * Input
+ *
+ * Description:
+ * This function accepts a single octets as the next message element.
+ *
+ * Parameters:
+ * message_element: [in]
+ * The next octet in the message.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void SHA1::Input(unsigned char message_element)
+{
+ Input(&message_element, 1);
+}
+
+/*
+ * Input
+ *
+ * Description:
+ * This function accepts a single octet as the next message element.
+ *
+ * Parameters:
+ * message_element: [in]
+ * The next octet in the message.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void SHA1::Input(char message_element)
+{
+ Input((unsigned char *) &message_element, 1);
+}
+
+/*
+ * operator<<
+ *
+ * Description:
+ * This operator makes it convenient to provide character strings to
+ * the SHA1 object for processing.
+ *
+ * Parameters:
+ * message_array: [in]
+ * The character array to take as input.
+ *
+ * Returns:
+ * A reference to the SHA1 object.
+ *
+ * Comments:
+ * Each character is assumed to hold 8 bits of information.
+ *
+ */
+SHA1& SHA1::operator<<(const char *message_array)
+{
+ const char *p = message_array;
+
+ while(*p)
+ {
+ Input(*p);
+ p++;
+ }
+
+ return *this;
+}
+
+/*
+ * operator<<
+ *
+ * Description:
+ * This operator makes it convenient to provide character strings to
+ * the SHA1 object for processing.
+ *
+ * Parameters:
+ * message_array: [in]
+ * The character array to take as input.
+ *
+ * Returns:
+ * A reference to the SHA1 object.
+ *
+ * Comments:
+ * Each character is assumed to hold 8 bits of information.
+ *
+ */
+SHA1& SHA1::operator<<(const unsigned char *message_array)
+{
+ const unsigned char *p = message_array;
+
+ while(*p)
+ {
+ Input(*p);
+ p++;
+ }
+
+ return *this;
+}
+
+/*
+ * operator<<
+ *
+ * Description:
+ * This function provides the next octet in the message.
+ *
+ * Parameters:
+ * message_element: [in]
+ * The next octet in the message
+ *
+ * Returns:
+ * A reference to the SHA1 object.
+ *
+ * Comments:
+ * The character is assumed to hold 8 bits of information.
+ *
+ */
+SHA1& SHA1::operator<<(const char message_element)
+{
+ Input((unsigned char *) &message_element, 1);
+
+ return *this;
+}
+
+/*
+ * operator<<
+ *
+ * Description:
+ * This function provides the next octet in the message.
+ *
+ * Parameters:
+ * message_element: [in]
+ * The next octet in the message
+ *
+ * Returns:
+ * A reference to the SHA1 object.
+ *
+ * Comments:
+ * The character is assumed to hold 8 bits of information.
+ *
+ */
+SHA1& SHA1::operator<<(const unsigned char message_element)
+{
+ Input(&message_element, 1);
+
+ return *this;
+}
+
+/*
+ * ProcessMessageBlock
+ *
+ * Description:
+ * This function will process the next 512 bits of the message
+ * stored in the Message_Block array.
+ *
+ * Parameters:
+ * None.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ * Many of the variable names in this function, especially the single
+ * character names, were used because those were the names used
+ * in the publication.
+ *
+ */
+void SHA1::ProcessMessageBlock()
+{
+ const unsigned K[] = { // Constants defined for SHA-1
+ 0x5A827999,
+ 0x6ED9EBA1,
+ 0x8F1BBCDC,
+ 0xCA62C1D6
+ };
+ int t; // Loop counter
+ unsigned temp; // Temporary word value
+ unsigned W[80]; // Word sequence
+ unsigned A, B, C, D, E; // Word buffers
+
+ /*
+ * Initialize the first 16 words in the array W
+ */
+ for(t = 0; t < 16; t++)
+ {
+ W[t] = ((unsigned) Message_Block[t * 4]) << 24;
+ W[t] |= ((unsigned) Message_Block[t * 4 + 1]) << 16;
+ W[t] |= ((unsigned) Message_Block[t * 4 + 2]) << 8;
+ W[t] |= ((unsigned) Message_Block[t * 4 + 3]);
+ }
+
+ for(t = 16; t < 80; t++)
+ {
+ W[t] = CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]);
+ }
+
+ A = H[0];
+ B = H[1];
+ C = H[2];
+ D = H[3];
+ E = H[4];
+
+ for(t = 0; t < 20; t++)
+ {
+ temp = CircularShift(5,A) + ((B & C) | ((~B) & D)) + E + W[t] + K[0];
+ temp &= 0xFFFFFFFF;
+ E = D;
+ D = C;
+ C = CircularShift(30,B);
+ B = A;
+ A = temp;
+ }
+
+ for(t = 20; t < 40; t++)
+ {
+ temp = CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1];
+ temp &= 0xFFFFFFFF;
+ E = D;
+ D = C;
+ C = CircularShift(30,B);
+ B = A;
+ A = temp;
+ }
+
+ for(t = 40; t < 60; t++)
+ {
+ temp = CircularShift(5,A) +
+ ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2];
+ temp &= 0xFFFFFFFF;
+ E = D;
+ D = C;
+ C = CircularShift(30,B);
+ B = A;
+ A = temp;
+ }
+
+ for(t = 60; t < 80; t++)
+ {
+ temp = CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3];
+ temp &= 0xFFFFFFFF;
+ E = D;
+ D = C;
+ C = CircularShift(30,B);
+ B = A;
+ A = temp;
+ }
+
+ H[0] = (H[0] + A) & 0xFFFFFFFF;
+ H[1] = (H[1] + B) & 0xFFFFFFFF;
+ H[2] = (H[2] + C) & 0xFFFFFFFF;
+ H[3] = (H[3] + D) & 0xFFFFFFFF;
+ H[4] = (H[4] + E) & 0xFFFFFFFF;
+
+ Message_Block_Index = 0;
+}
+
+/*
+ * PadMessage
+ *
+ * Description:
+ * According to the standard, the message must be padded to an even
+ * 512 bits. The first padding bit must be a '1'. The last 64 bits
+ * represent the length of the original message. All bits in between
+ * should be 0. This function will pad the message according to those
+ * rules by filling the message_block array accordingly. It will also
+ * call ProcessMessageBlock() appropriately. When it returns, it
+ * can be assumed that the message digest has been computed.
+ *
+ * Parameters:
+ * None.
+ *
+ * Returns:
+ * Nothing.
+ *
+ * Comments:
+ *
+ */
+void SHA1::PadMessage()
+{
+ /*
+ * Check to see if the current message block is too small to hold
+ * the initial padding bits and length. If so, we will pad the
+ * block, process it, and then continue padding into a second block.
+ */
+ if (Message_Block_Index > 55)
+ {
+ Message_Block[Message_Block_Index++] = 0x80;
+ while(Message_Block_Index < 64)
+ {
+ Message_Block[Message_Block_Index++] = 0;
+ }
+
+ ProcessMessageBlock();
+
+ while(Message_Block_Index < 56)
+ {
+ Message_Block[Message_Block_Index++] = 0;
+ }
+ }
+ else
+ {
+ Message_Block[Message_Block_Index++] = 0x80;
+ while(Message_Block_Index < 56)
+ {
+ Message_Block[Message_Block_Index++] = 0;
+ }
+
+ }
+
+ /*
+ * Store the message length as the last 8 octets
+ */
+ Message_Block[56] = (Length_High >> 24) & 0xFF;
+ Message_Block[57] = (Length_High >> 16) & 0xFF;
+ Message_Block[58] = (Length_High >> 8) & 0xFF;
+ Message_Block[59] = (Length_High) & 0xFF;
+ Message_Block[60] = (Length_Low >> 24) & 0xFF;
+ Message_Block[61] = (Length_Low >> 16) & 0xFF;
+ Message_Block[62] = (Length_Low >> 8) & 0xFF;
+ Message_Block[63] = (Length_Low) & 0xFF;
+
+ ProcessMessageBlock();
+}
+
+
+/*
+ * CircularShift
+ *
+ * Description:
+ * This member function will perform a circular shifting operation.
+ *
+ * Parameters:
+ * bits: [in]
+ * The number of bits to shift (1-31)
+ * word: [in]
+ * The value to shift (assumes a 32-bit integer)
+ *
+ * Returns:
+ * The shifted value.
+ *
+ * Comments:
+ *
+ */
+unsigned SHA1::CircularShift(int bits, unsigned word)
+{
+ return ((word << bits) & 0xFFFFFFFF) | ((word & 0xFFFFFFFF) >> (32-bits));
+}
+
+} \ No newline at end of file
diff --git a/src/sha1.hpp b/src/sha1.hpp
new file mode 100644
index 0000000..7f50827
--- /dev/null
+++ b/src/sha1.hpp
@@ -0,0 +1,93 @@
+/*
+ * sha1.h
+ *
+ * Copyright (C) 1998, 2009
+ * Paul E. Jones <paulej@packetizer.com>
+ * All Rights Reserved.
+ *
+ *****************************************************************************
+ * $Id: sha1.h 12 2009-06-22 19:34:25Z paulej $
+ *****************************************************************************
+ *
+ * Description:
+ * This class implements the Secure Hashing Standard as defined
+ * in FIPS PUB 180-1 published April 17, 1995.
+ *
+ * Many of the variable names in this class, especially the single
+ * character names, were used because those were the names used
+ * in the publication.
+ *
+ * Please read the file sha1.cpp for more information.
+ *
+ */
+
+#ifndef _SHA1_H_
+#define _SHA1_H_
+
+namespace sha
+{
+
+class SHA1
+{
+
+ public:
+
+ SHA1();
+ virtual ~SHA1();
+
+ /*
+ * Re-initialize the class
+ */
+ void Reset();
+
+ /*
+ * Returns the message digest
+ */
+ bool Result(unsigned *message_digest_array);
+
+ /*
+ * Provide input to SHA1
+ */
+ void Input( const unsigned char *message_array,
+ unsigned length);
+ void Input( const char *message_array,
+ unsigned length);
+ void Input(unsigned char message_element);
+ void Input(char message_element);
+ SHA1& operator<<(const char *message_array);
+ SHA1& operator<<(const unsigned char *message_array);
+ SHA1& operator<<(const char message_element);
+ SHA1& operator<<(const unsigned char message_element);
+
+ private:
+
+ /*
+ * Process the next 512 bits of the message
+ */
+ void ProcessMessageBlock();
+
+ /*
+ * Pads the current message block to 512 bits
+ */
+ void PadMessage();
+
+ /*
+ * Performs a circular left shift operation
+ */
+ inline unsigned CircularShift(int bits, unsigned word);
+
+ unsigned H[5]; // Message digest buffers
+
+ unsigned Length_Low; // Message length in bits
+ unsigned Length_High; // Message length in bits
+
+ unsigned char Message_Block[64]; // 512-bit message blocks
+ int Message_Block_Index; // Index into message block array
+
+ bool Computed; // Is the digest computed?
+ bool Corrupted; // Is the message digest corruped?
+
+};
+}
+
+#endif
diff --git a/src/strusCms.cpp b/src/strusCms.cpp
index e5792ec..137a209 100644
--- a/src/strusCms.cpp
+++ b/src/strusCms.cpp
@@ -10,7 +10,13 @@ strusCms::strusCms( cppcms::service &srv )
: cppcms::application( srv ),
intro( *this ),
user( *this ),
- conn( settings( ).get<std::string>( "strusCms.db_connection" ) )
+ conn( settings( ).get<std::string>( "strusCms.db_connection" ) ),
+ mail( settings( ).get<std::string>( "strusCms.mail.server" ),
+ settings( ).get<unsigned short>( "strusCms.mail.port" ),
+ settings( ).get<std::string>( "strusCms.mail.username" ),
+ settings( ).get<std::string>( "strusCms.mail.password" ),
+ settings( ).get<std::string>( "strusCms.mail.from" )
+ )
{
locale_name = "en";
script = settings( ).get<std::string>( "strusCms.script" );
diff --git a/src/strusCms.hpp b/src/strusCms.hpp
index 9a93e99..579b2d7 100644
--- a/src/strusCms.hpp
+++ b/src/strusCms.hpp
@@ -5,6 +5,7 @@
#include "intro.hpp"
#include "user.hpp"
+#include "mail.hpp"
namespace apps {
@@ -17,11 +18,11 @@ class strusCms : public cppcms::application {
apps::intro intro;
apps::user user;
std::string conn;
+ mailer mail;
private:
std::string script;
std::string locale_name;
-
};
}
diff --git a/src/user.cpp b/src/user.cpp
index 5b53416..3541eba 100644
--- a/src/user.cpp
+++ b/src/user.cpp
@@ -2,6 +2,7 @@
#include "user.hpp"
#include "strusCms.hpp"
#include "captcha.hpp"
+#include "sha1.hpp"
#include <cppcms/url_dispatcher.h>
#include <cppcms/url_mapper.h>
@@ -9,6 +10,10 @@
#include <cppcms/session_interface.h>
#include <booster/posix_time.h>
+#include <cstdlib>
+#include <sstream>
+#include <iomanip>
+
namespace apps {
// user
@@ -63,9 +68,29 @@ void user::register_user( )
if( request( ).request_method( ) == "POST" ) {
c.register_user.load( context( ) );
if( c.register_user.validate( ) ) {
- response( ).set_redirect_header( cms.root( ) + "/confirm_register" );
+ std::string code = registration_start( c.register_user.username.value( ),
+ c.register_user.password.value( ), c.register_user.email.value( ) );
+
+ cms.mail.subject = "Registration request";
+
+ std::ostringstream oss;
+ oss << "Your registration code is: " << code << "\n";
+
+ cms.mail.body = oss.str( );
+ cms.mail.to = c.register_user.email.value( );
+ cms.mail.send( );
+ if( cms.mail.hasError( ) ) {
+ c.register_user.email.valid( false );
+ c.register_user.email.error_message( "Can't send email to this address" );
+ booster::ptime::sleep( booster::ptime( 5, 0 ) );
+ delete_user( c.register_user.username.value( ) );
+ std::cerr << "SEND MAIL ERROR: " << cms.mail.getLastError( ) << std::endl;
+ } else {
+ response( ).set_redirect_header( cms.root( ) + "/confirm_register" );
+ }
}
}
+
render( "register_user", c );
}
@@ -76,14 +101,20 @@ void user::confirm_register( )
if( request( ).request_method( ) == "POST" ) {
c.confirm_register.load( context( ) );
if( c.confirm_register.validate( ) ) {
- response( ).set_redirect_header( cms.root( ) + "/login" );
+ if( cms.user.verify_registration_code( c.confirm_register.code.value( ) ) ) {
+ response( ).set_redirect_header( cms.root( ) + "/login" );
+ } else {
+ booster::ptime::sleep( booster::ptime( 5, 0 ) );
+ c.confirm_register.code.valid( false );
+ }
}
}
+
render( "confirm_register", c );
}
// TODO: make this a salted hash
-bool user::check_login( std::string user, std::string password )
+bool user::check_login( const std::string user, const std::string password )
{
if( user.empty( ) || password.empty( ) ) {
return false;
@@ -116,7 +147,7 @@ bool user::check_login( std::string user, std::string password )
return true;
}
-bool user::user_exists( std::string user )
+bool user::user_exists( const std::string user )
{
if( user.empty( ) ) {
return false;
@@ -132,6 +163,75 @@ bool user::user_exists( std::string user )
return true;
}
+namespace {
+
+std::string generate_token( )
+{
+ char chars[] = "ABCDEF1234567890";
+ std::string token;
+
+ for( int i = 0; i < 12; i++ ) {
+ token += chars[rand( ) % 16];
+ }
+
+ return token;
+}
+
+std::string compute_token_hash( const std::string user, const std::string token )
+{
+ sha::SHA1 sha;
+ unsigned int res[5];
+ sha.Reset( );
+ sha << user.c_str( ) << token.c_str( );
+
+ std::ostringstream oss;
+ for( int i = 0; i < 5; i++ ) {
+ oss << std::uppercase << std::hex << std::setw( 8 ) << std::setfill( '0' ) << res[i];
+ if( i < 4 ) oss << ' ';
+ }
+
+ return oss.str( );
+}
+
+}
+
+std::string user::registration_start( const std::string user, const std::string password, const std::string email )
+{
+ std::time_t now_time = std::time( 0 );
+ std::tm now = *std::localtime( &now_time );
+ std::string token = generate_token( );
+ std::string code = compute_token_hash( user, token );
+
+ cppdb::session sql( cms.conn );
+ cppdb::statement stmt;
+ stmt = sql << "INSERT INTO user(username, password, email, status, registration_start, code ) VALUES( ?, ?, ?, 'R', ?, ? )"
+ << user << password << email << now << code;
+ stmt.exec( );
+
+ return code;
+}
+
+bool user::verify_registration_code( std::string code )
+{
+ cppdb::session sql( cms.conn );
+ cppdb::statement stmt;
+ stmt = sql << "UPDATE user set status='A' WHERE code=?" << code;
+ stmt.exec( );
+ if( stmt.affected( ) == 1 ) {
+ return true;
+ }
+
+ return false;
+}
+
+void user::delete_user( std::string user )
+{
+ cppdb::session sql( cms.conn );
+ cppdb::statement stmt;
+ stmt = sql << "DELETE FROM user WHERE username=?" << user;
+ stmt.exec( );
+}
+
void user::ini( content::user &c )
{
master::ini( c );
@@ -247,6 +347,7 @@ bool register_user_form::validate( )
if( captcha.value( ).compare( cms.user.last_captcha ) != 0 ) {
captcha.valid( false );
captcha.clear( );
+ booster::ptime::sleep( booster::ptime( 5, 0 ) );
return false;
}
@@ -273,15 +374,6 @@ bool confirm_register_form::validate( )
if( !form::validate( ) ) {
return false;
}
-
- // TODO: check code supplied against code in the DB, this is a
- // method in the user class
-
- //~ if( !cms.user.check_code( code.value( ) ) ) {
- //~ code.valid( false );
- //~ booster::ptime::sleep( booster::ptime( 5, 0 ) );
- //~ return false;
- //~ }
return true;
}
diff --git a/src/user.hpp b/src/user.hpp
index 633af60..e6a4e35 100644
--- a/src/user.hpp
+++ b/src/user.hpp
@@ -10,8 +10,11 @@ namespace apps {
class user : public master {
public:
user( strusCms &cms );
- bool check_login( std::string user, std::string password );
- bool user_exists( std::string user );
+ bool check_login( const std::string user, const std::string password );
+ bool user_exists( const std::string user );
+ void delete_user( const std::string user );
+ std::string registration_start( const std::string user, const std::string password, const std::string email );
+ bool verify_registration_code( const std::string code );
public:
std::string last_captcha;
diff --git a/templates/master.tmpl b/templates/master.tmpl
index b80d0f9..220e840 100644
--- a/templates/master.tmpl
+++ b/templates/master.tmpl
@@ -24,6 +24,8 @@
<li><a href="http://cppcms.com/wikipp/en/page/main">CppCMS</a><br/>a C++ web programming framework</li>
<li><a href="http://brokestream.com/captcha.html"</li>libcaptcha</a><br/>a C standalone Captcha generator</li>
<li><a href="http://libb64.sourceforge.net/"</li>libb64</a><br/>a BASE64 encoder/decoder library</li>
+ <li><a href="http://sourceforge.net/projects/libquickmail/"</li>libquickmail</a><br/>a library to send emails</li>
+ <li><a href="http://www.packetizer.com/security/sha1/"</li>sha1</a><br/>a SHA1 implementation</li>
</ul>
</div>
@@ -37,7 +39,7 @@
<% include page_content( ) %>
<p class="credits">&copy; 2015 Patrick Frey<br />
- Template design by <a href="http://andreasviklund.com/">Andreas Viklund</a> / Best hosted at <a href="https://www.svenskadomaner.se/?ref=mall&amp;ling=en" title="Svenska Domäner AB">www.svenskadomaner.se</a></p>
+ Template design by <a href="http://andreasviklund.com/">Andreas Viklund</a> / Best hosted at <a href="https://www.svenskadomaner.se/?ref=mall&amp;ling=en" title="Svenska Domner AB">www.svenskadomaner.se</a></p>
</div>
</body>