summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2015-04-29 18:58:07 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2015-04-29 18:58:07 +0200
commitcb69299b9d59db0888e942025ae4915c6f32d066 (patch)
treefcb85301442a9eda1ed9d60a8ba52d8c60f11114
parentfa132310bf61c115907e5c237333207f308b1de4 (diff)
downloadaCms-cb69299b9d59db0888e942025ae4915c6f32d066.tar.gz
aCms-cb69299b9d59db0888e942025ae4915c6f32d066.tar.bz2
added libquickmail and email registration
-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--CMakeLists.txt5
-rw-r--r--LINKS7
-rw-r--r--config.js7
-rw-r--r--src/mail.cpp39
-rw-r--r--src/mail.hpp29
-rw-r--r--src/strusCms.cpp8
-rw-r--r--src/strusCms.hpp3
-rw-r--r--src/user.cpp10
-rw-r--r--src/user_content.hpp1
-rw-r--r--templates/confirm_register.tmpl7
-rw-r--r--templates/master.tmpl3
22 files changed, 2937 insertions, 6 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/CMakeLists.txt b/CMakeLists.txt
index e6cc8f6..6667fee 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,6 +46,7 @@ set(SRC
src/master.cpp
src/intro.cpp
src/captcha.cpp
+ src/mail.cpp
src/user.cpp
)
@@ -67,7 +69,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/LINKS b/LINKS
index 3d68afd..a575abf 100644
--- a/LINKS
+++ b/LINKS
@@ -11,4 +11,9 @@ https://github.com/allan-simon/tatoebacpp
captcha generator (standalone, sweat, no Imagemagick or fonts needed):
http://brokestream.com/captcha.html
-http://www.cthulhulives.org/toybox/PROPDOCS/PropFonts.html \ No newline at end of file
+http://www.cthulhulives.org/toybox/PROPDOCS/PropFonts.html
+
+SMTP:
+
+https://www.cs.auckland.ac.nz/~pgut001/cryptlib/download.html
+http://sourceforge.net/projects/libquickmail/
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/src/mail.cpp b/src/mail.cpp
new file mode 100644
index 0000000..84e1210
--- /dev/null
+++ b/src/mail.cpp
@@ -0,0 +1,39 @@
+#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, "plain/text", const_cast<char *>( body.c_str( ) ), body.size( ), 0 );
+ }
+
+ const char *errmsg;
+ errmsg = quickmail_send( mailobj, server.c_str( ), port, username.c_str( ), password.c_str( ) );
+ std::cerr << "ERROR: " << errmsg << std::endl;
+}
+
diff --git a/src/mail.hpp b/src/mail.hpp
new file mode 100644
index 0000000..c9bd8ef
--- /dev/null
+++ b/src/mail.hpp
@@ -0,0 +1,29 @@
+#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;
+
+ 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( );
+};
+
+
+#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 dddde30..3a21504 100644
--- a/src/user.cpp
+++ b/src/user.cpp
@@ -63,9 +63,14 @@ void user::register_user( )
if( request( ).request_method( ) == "POST" ) {
c.register_user.load( context( ) );
if( c.register_user.validate( ) ) {
+ cms.mail.subject = "Registration request";
+ cms.mail.body = "Your registration code is: CODE";
+ cms.mail.to = c.register_user.email.value( );
+ cms.mail.send( );
response( ).set_redirect_header( cms.root( ) + "/confirm_register" );
}
}
+
render( "register_user", c );
}
@@ -202,6 +207,8 @@ register_user_form::register_user_form( apps::strusCms &cms )
password.error_message( "Your password is illegal" );
password2.message( "Your password (again)" );
password2.error_message( "Your password doesn't match" );
+ email.message( "Email" );
+ email.error_message( "Your email address is not valid" );
captcha.message( "Enter the correct captcha" );
captcha.error_message( "Captcha didn't match" );
submit.value( "Register user" );
@@ -209,12 +216,14 @@ register_user_form::register_user_form( apps::strusCms &cms )
add( username );
add( password );
add( password2 );
+ add( email );
add( captcha );
add( submit );
username.non_empty( );
password.non_empty( );
password2.non_empty( );
+ email.non_empty( );
captcha.non_empty( );
}
@@ -243,6 +252,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;
}
diff --git a/src/user_content.hpp b/src/user_content.hpp
index e86e2fd..756f314 100644
--- a/src/user_content.hpp
+++ b/src/user_content.hpp
@@ -24,6 +24,7 @@ struct register_user_form : public cppcms::form {
cppcms::widgets::text username;
cppcms::widgets::password password;
cppcms::widgets::password password2;
+ cppcms::widgets::text email;
cppcms::widgets::text captcha;
cppcms::widgets::submit submit;
diff --git a/templates/confirm_register.tmpl b/templates/confirm_register.tmpl
index 8b41290..820f6f4 100644
--- a/templates/confirm_register.tmpl
+++ b/templates/confirm_register.tmpl
@@ -14,9 +14,14 @@
<% form as_table confirm_register %>
</table>
</form>
-
+ </div>
+ <div>
If you entered the correct code, you can try to log in.
</div>
+ <div>
+ If you don't get a code via email, contact the webmaster of this
+ site.
+ </div>
<% end template %>
<% end view %>
diff --git a/templates/master.tmpl b/templates/master.tmpl
index b80d0f9..0f42360 100644
--- a/templates/master.tmpl
+++ b/templates/master.tmpl
@@ -24,6 +24,7 @@
<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>
</ul>
</div>
@@ -37,7 +38,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>