diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/advance/UnknownSignersChecker.h | 52 | ||||
-rw-r--r-- | src/server/BaseAPI.h | 73 | ||||
-rw-r--r-- | src/server/ComUtils.h | 83 | ||||
-rw-r--r-- | src/server/api/PubkeyGetter.h | 57 | ||||
-rw-r--r-- | src/server/api/PubkeyUploader.h | 58 | ||||
-rw-r--r-- | src/smtp/SmtpMime | 31 | ||||
-rw-r--r-- | src/smtp/emailaddress.h | 63 | ||||
-rw-r--r-- | src/smtp/mimeattachment.h | 51 | ||||
-rw-r--r-- | src/smtp/mimecontentformatter.h | 43 | ||||
-rw-r--r-- | src/smtp/mimefile.h | 63 | ||||
-rw-r--r-- | src/smtp/mimehtml.h | 61 | ||||
-rw-r--r-- | src/smtp/mimeinlinefile.h | 56 | ||||
-rw-r--r-- | src/smtp/mimemessage.h | 110 | ||||
-rw-r--r-- | src/smtp/mimemultipart.h | 71 | ||||
-rw-r--r-- | src/smtp/mimepart.h | 110 | ||||
-rw-r--r-- | src/smtp/mimetext.h | 62 | ||||
-rw-r--r-- | src/smtp/quotedprintable.h | 39 | ||||
-rw-r--r-- | src/smtp/smtpclient.h | 197 | ||||
-rw-r--r-- | src/smtp/smtpexports.h | 10 |
19 files changed, 1290 insertions, 0 deletions
diff --git a/src/advance/UnknownSignersChecker.h b/src/advance/UnknownSignersChecker.h new file mode 100644 index 00000000..56085265 --- /dev/null +++ b/src/advance/UnknownSignersChecker.h @@ -0,0 +1,52 @@ +/** + * This file is part of GPGFrontend. + * + * GPGFrontend 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_ZH_CN_TS_UNKNOWNSIGNERSCHECKER_H +#define GPGFRONTEND_ZH_CN_TS_UNKNOWNSIGNERSCHECKER_H + +#include "server/api/PubkeyGetter.h" + +class UnknownSignersChecker : public QObject { +Q_OBJECT +public: + + UnknownSignersChecker(GpgFrontend::GpgContext *ctx, gpgme_verify_result_t result); + + void start(); + +private: + + QString appPath; + QSettings settings; + GpgFrontend::GpgContext *mCtx; + gpgme_verify_result_t mResult; + + QVector<QString> unknownFprs; + + void check_signer(gpgme_signature_t sign); + +}; + + +#endif //GPGFRONTEND_ZH_CN_TS_UNKNOWNSIGNERSCHECKER_H diff --git a/src/server/BaseAPI.h b/src/server/BaseAPI.h new file mode 100644 index 00000000..0b724bbc --- /dev/null +++ b/src/server/BaseAPI.h @@ -0,0 +1,73 @@ +/** + * This file is part of GPGFrontend. + * + * GPGFrontend 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_ZH_CN_TS_BASEAPI_H +#define GPGFRONTEND_ZH_CN_TS_BASEAPI_H + +#include "GpgFrontend.h" +#include "ComUtils.h" + +#include "rapidjson/document.h" + +class BaseAPI : public QObject { +Q_OBJECT +public: + + explicit BaseAPI(ComUtils::ServiceType serviceType); + + ~BaseAPI() override; + + void start(); + + void refresh(); + + [[nodiscard]] bool result() const; + +private: + + ComUtils *utils; + + QUrl reqUrl; + + QNetworkRequest request; + + QNetworkReply *send_json_data(); + +protected: + + bool good = false; + + rapidjson::Document document; + + const ComUtils &getUtils() { return *utils; }; + + virtual void construct_json() = 0; + + virtual void deal_reply() = 0; + + +}; + + +#endif //GPGFRONTEND_ZH_CN_TS_BASEAPI_H diff --git a/src/server/ComUtils.h b/src/server/ComUtils.h new file mode 100644 index 00000000..1f71f2e6 --- /dev/null +++ b/src/server/ComUtils.h @@ -0,0 +1,83 @@ +/** + * This file is part of GPGFrontend. + * + * GPGFrontend 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_ZH_CN_TS_COMUTILS_H +#define GPGFRONTEND_ZH_CN_TS_COMUTILS_H + +#include "GpgFrontend.h" +#include "gpg/GpgContext.h" +#include "rapidjson/document.h" + +namespace GpgFrontend { + + class ComUtils : public QWidget { + Q_OBJECT + public: + + enum ServiceType { GetServiceToken, ShortenCryptText, GetFullCryptText, UploadPubkey, GetPubkey }; + + explicit ComUtils(QWidget *parent) : QWidget(parent), appPath(qApp->applicationDirPath()), + settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", + QSettings::IniFormat) { + + } + + [[nodiscard]] QString getUrl(ServiceType type) const; + + bool checkServerReply(const QByteArray &reply); + + [[nodiscard]] QString getDataValueStr(const QString &key) const; + + [[nodiscard]] bool checkDataValueStr(const QString &key) const; + + [[nodiscard]] const rapidjson::Value &getDataValue(const QString &key) const; + + [[nodiscard]] bool checkDataValue(const QString &key) const; + + [[nodiscard]] bool checkServiceTokenFormat(const QString& serviceToken) const; + + static QByteArray getSignStringBase64(GpgFrontend::GpgContext *ctx, const QString &str, const GpgKey& key); + + [[nodiscard]] bool good() const { return is_good; } + + QNetworkAccessManager &getNetworkManager() {return networkMgr;} + + void clear(); + + private: + + QString appPath; + QSettings settings; + rapidjson::Document replyDoc; + rapidjson::Value dataVal; + QNetworkAccessManager networkMgr; + QRegularExpression re_uuid{R"(\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b)"}; + + bool is_good = false; + }; + +} + + +#endif //GPGFRONTEND_ZH_CN_TS_COMUTILS_H diff --git a/src/server/api/PubkeyGetter.h b/src/server/api/PubkeyGetter.h new file mode 100644 index 00000000..216b1ef2 --- /dev/null +++ b/src/server/api/PubkeyGetter.h @@ -0,0 +1,57 @@ +/** + * This file is part of GPGFrontend. + * + * GPGFrontend 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_ZH_CN_TS_PUBKEYGETTER_H +#define GPGFRONTEND_ZH_CN_TS_PUBKEYGETTER_H + +#include "GpgFrontend.h" +#include "server/BaseAPI.h" +#include "gpg/GpgContext.h" + +class ComUtils; + +/** + * Get and Import Pubkey from server + */ +class PubkeyGetter : public BaseAPI { +public: + + PubkeyGetter(GpgFrontend::GpgContext *ctx, const QVector<QString> &fprs); + +private: + + GpgFrontend::GpgContext *mCtx; + + const QVector<QString> &mFprs; + +protected: + + void construct_json() final; + + void deal_reply() final; + +}; + + +#endif //GPGFRONTEND_ZH_CN_TS_PUBKEYGETTER_H diff --git a/src/server/api/PubkeyUploader.h b/src/server/api/PubkeyUploader.h new file mode 100644 index 00000000..61096d46 --- /dev/null +++ b/src/server/api/PubkeyUploader.h @@ -0,0 +1,58 @@ +/** + * This file is part of GPGFrontend. + * + * GPGFrontend 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. + * + * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric<[email protected]> starting on May 12, 2021. + * + */ + +#ifndef GPGFRONTEND_ZH_CN_TS_PUBKEYUPLOADER_H +#define GPGFRONTEND_ZH_CN_TS_PUBKEYUPLOADER_H + +#include "GpgFrontend.h" +#include "server/BaseAPI.h" +#include "gpg/GpgContext.h" + +#include "rapidjson/document.h" + +/** + * Upload pubkey into server + */ +class PubkeyUploader : public BaseAPI { +public: + + PubkeyUploader(GpgFrontend::GpgContext *ctx, const QVector<GpgKey> &keys); + +private: + + const QVector<GpgKey> &mKeys; + + GpgFrontend::GpgContext *mCtx; + +protected: + + void construct_json() final; + + void deal_reply() final; + + +}; + + +#endif //GPGFRONTEND_ZH_CN_TS_PUBKEYUPLOADER_H diff --git a/src/smtp/SmtpMime b/src/smtp/SmtpMime new file mode 100644 index 00000000..940996b8 --- /dev/null +++ b/src/smtp/SmtpMime @@ -0,0 +1,31 @@ +/* + Copyright (c) 2011-2012 - Tőkés Attila + + This file is part of SmtpClient for Qt. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + See the LICENSE file for more details. +*/ + +#ifndef SMTPMIME_H +#define SMTPMIME_H + +#include "smtpclient.h" +#include "mimepart.h" +#include "mimehtml.h" +#include "mimeattachment.h" +#include "mimemessage.h" +#include "mimetext.h" +#include "mimeinlinefile.h" +#include "mimefile.h" + +#endif // SMTPMIME_H diff --git a/src/smtp/emailaddress.h b/src/smtp/emailaddress.h new file mode 100644 index 00000000..90e4c1e9 --- /dev/null +++ b/src/smtp/emailaddress.h @@ -0,0 +1,63 @@ +/* + Copyright (c) 2011-2012 - Tőkés Attila + + This file is part of SmtpClient for Qt. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + See the LICENSE file for more details. +*/ + +#ifndef EMAILADDRESS_H +#define EMAILADDRESS_H + +#include <QObject> + +#include "smtpexports.h" + +class SMTP_EXPORT EmailAddress : public QObject { +Q_OBJECT +public: + + /* [1] Constructors and Destructors */ + + EmailAddress() = default; + + explicit EmailAddress(const QString &address, const QString &name = ""); + + ~EmailAddress() override; + + /* [1] --- */ + + + /* [2] Getters and Setters */ + void setName(const QString &name); + + void setAddress(const QString &address); + + [[nodiscard]] const QString &getName() const; + + [[nodiscard]] const QString &getAddress() const; + + /* [2] --- */ + + +private: + + /* [3] Private members */ + + QString name; + QString address; + + /* [3] --- */ +}; + +#endif // EMAILADDRESS_H diff --git a/src/smtp/mimeattachment.h b/src/smtp/mimeattachment.h new file mode 100644 index 00000000..6b98a65a --- /dev/null +++ b/src/smtp/mimeattachment.h @@ -0,0 +1,51 @@ +/* + Copyright (c) 2011-2012 - Tőkés Attila + + This file is part of SmtpClient for Qt. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + See the LICENSE file for more details. +*/ + +#ifndef MIMEATTACHMENT_H +#define MIMEATTACHMENT_H + +#include <QFile> +#include "mimepart.h" +#include "mimefile.h" + +#include "smtpexports.h" + +class SMTP_EXPORT MimeAttachment : public MimeFile { +Q_OBJECT +public: + + /* [1] Constructors and Destructors */ + + explicit MimeAttachment(QFile *file); + + MimeAttachment(const QByteArray &stream, const QString &fileName); + + ~MimeAttachment() override; + + /* [1] --- */ + +protected: + + /* [2] Protected methods */ + + void prepare() override; + + /* [2] --- */ +}; + +#endif // MIMEATTACHMENT_H diff --git a/src/smtp/mimecontentformatter.h b/src/smtp/mimecontentformatter.h new file mode 100644 index 00000000..e6e3637f --- /dev/null +++ b/src/smtp/mimecontentformatter.h @@ -0,0 +1,43 @@ +/* + Copyright (c) 2011-2012 - Tőkés Attila + + This file is part of SmtpClient for Qt. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + See the LICENSE file for more details. +*/ + +#ifndef MIMECONTENTFORMATTER_H +#define MIMECONTENTFORMATTER_H + +#include <QObject> +#include <QByteArray> + +#include "smtpexports.h" + +class SMTP_EXPORT MimeContentFormatter : public QObject { +Q_OBJECT +public: + explicit MimeContentFormatter(int max_length = 76); + + void setMaxLength(int l); + + [[nodiscard]] int getMaxLength() const; + + [[nodiscard]] QString format(const QString &content, bool quotedPrintable = false) const; + +protected: + int max_length; + +}; + +#endif // MIMECONTENTFORMATTER_H diff --git a/src/smtp/mimefile.h b/src/smtp/mimefile.h new file mode 100644 index 00000000..46903da9 --- /dev/null +++ b/src/smtp/mimefile.h @@ -0,0 +1,63 @@ +/* + Copyright (c) 2011-2012 - Tőkés Attila + + This file is part of SmtpClient for Qt. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + See the LICENSE file for more details. +*/ + +#ifndef MIMEFILE_H +#define MIMEFILE_H + +#include "mimepart.h" +#include <QFile> + +#include "smtpexports.h" + +class SMTP_EXPORT MimeFile : public MimePart { +Q_OBJECT +public: + + /* [1] Constructors and Destructors */ + + MimeFile(const QByteArray &stream, const QString &fileName); + + explicit MimeFile(QFile *f); + + ~MimeFile() override; + + /* [1] --- */ + + + /* [2] Getters and Setters */ + + /* [2] --- */ + +protected: + + /* [3] Protected members */ + + QFile *file; + + /* [3] --- */ + + + /* [4] Protected methods */ + + void prepare() override; + + /* [4] --- */ + +}; + +#endif // MIMEFILE_H diff --git a/src/smtp/mimehtml.h b/src/smtp/mimehtml.h new file mode 100644 index 00000000..8ce8c454 --- /dev/null +++ b/src/smtp/mimehtml.h @@ -0,0 +1,61 @@ +/* + Copyright (c) 2011-2012 - Tőkés Attila + + This file is part of SmtpClient for Qt. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + See the LICENSE file for more details. +*/ + +#ifndef MIMEHTML_H +#define MIMEHTML_H + +#include "mimetext.h" + +#include "smtpexports.h" + +class SMTP_EXPORT MimeHtml : public MimeText { +Q_OBJECT +public: + + /* [1] Constructors and Destructors */ + + explicit MimeHtml(const QString &html = ""); + + ~MimeHtml() override; + + /* [1] --- */ + + + /* [2] Getters and Setters */ + + void setHtml(const QString &html); + + [[nodiscard]] const QString &getHtml() const; + + /* [2] --- */ + +protected: + + /* [3] Protected members */ + + /* [3] --- */ + + + /* [4] Protected methods */ + + void prepare() override; + + /* [4] --- */ +}; + +#endif // MIMEHTML_H diff --git a/src/smtp/mimeinlinefile.h b/src/smtp/mimeinlinefile.h new file mode 100644 index 00000000..916f7b76 --- /dev/null +++ b/src/smtp/mimeinlinefile.h @@ -0,0 +1,56 @@ +/* + Copyright (c) 2011-2012 - Tőkés Attila + + This file is part of SmtpClient for Qt. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + See the LICENSE file for more details. +*/ + +#ifndef MIMEINLINEFILE_H +#define MIMEINLINEFILE_H + +#include "mimefile.h" + +#include "smtpexports.h" + +class SMTP_EXPORT MimeInlineFile : public MimeFile { +public: + + /* [1] Constructors and Destructors */ + + explicit MimeInlineFile(QFile *f); + + ~MimeInlineFile() override; + + /* [1] --- */ + + + /* [2] Getters and Setters */ + + /* [2] --- */ + +protected: + + /* [3] Protected members */ + + /* [3] --- */ + + + /* [4] Protected methods */ + + void prepare() override; + + /* [4] --- */ +}; + +#endif // MIMEINLINEFILE_H diff --git a/src/smtp/mimemessage.h b/src/smtp/mimemessage.h new file mode 100644 index 00000000..24e4f108 --- /dev/null +++ b/src/smtp/mimemessage.h @@ -0,0 +1,110 @@ +/* + Copyright (c) 2011-2012 - Tőkés Attila + + This file is part of SmtpClient for Qt. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + See the LICENSE file for more details. +*/ + +#ifndef MIMEMESSAGE_H +#define MIMEMESSAGE_H + +#include "mimepart.h" +#include "mimemultipart.h" +#include "emailaddress.h" +#include <QList> + +#include "smtpexports.h" + +class SMTP_EXPORT MimeMessage : public QObject { +public: + + enum RecipientType { + To, // primary + Cc, // carbon copy + Bcc // blind carbon copy + }; + + /* [1] Constructors and Destructors */ + + explicit MimeMessage(bool createAutoMimeConent = true); + + ~MimeMessage() override; + + /* [1] --- */ + + + /* [2] Getters and Setters */ + + void setSender(EmailAddress *e); + + void addRecipient(EmailAddress *rcpt, RecipientType type = To); + + void addTo(EmailAddress *rcpt); + + void addCc(EmailAddress *rcpt); + + void addBcc(EmailAddress *rcpt); + + void setSubject(const QString &subject); + + void addPart(MimePart *part); + + void setReplyTo(EmailAddress *rto); + + void setInReplyTo(const QString &inReplyTo); + + void setHeaderEncoding(MimePart::Encoding); + + [[nodiscard]] const EmailAddress &getSender() const; + + [[nodiscard]] const QList<EmailAddress *> &getRecipients(RecipientType type = To) const; + + [[nodiscard]] const QString &getSubject() const; + + [[nodiscard]] const QList<MimePart *> &getParts() const; + + [[nodiscard]] const EmailAddress *getReplyTo() const; + + MimePart &getContent(); + + void setContent(MimePart *content); + /* [2] --- */ + + + /* [3] Public methods */ + + virtual QString toString(); + + /* [3] --- */ + +protected: + + /* [4] Protected members */ + + EmailAddress *sender{}; + EmailAddress *replyTo; + QList<EmailAddress *> recipientsTo, recipientsCc, recipientsBcc; + QString subject; + QString mInReplyTo; + MimePart *content; + bool autoMimeContentCreated; + + MimePart::Encoding hEncoding; + + /* [4] --- */ + + +}; + +#endif // MIMEMESSAGE_H diff --git a/src/smtp/mimemultipart.h b/src/smtp/mimemultipart.h new file mode 100644 index 00000000..b829a66f --- /dev/null +++ b/src/smtp/mimemultipart.h @@ -0,0 +1,71 @@ +/* + Copyright (c) 2011-2012 - Tőkés Attila + + This file is part of SmtpClient for Qt. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + See the LICENSE file for more details. +*/ + +#ifndef MIMEMULTIPART_H +#define MIMEMULTIPART_H + +#include "mimepart.h" + +#include "smtpexports.h" + +class SMTP_EXPORT MimeMultiPart : public MimePart { +Q_OBJECT +public: + /* [0] Enums */ + enum MultiPartType { + Mixed = 0, // RFC 2046, section 5.1.3 + Digest = 1, // RFC 2046, section 5.1.5 + Alternative = 2, // RFC 2046, section 5.1.4 + Related = 3, // RFC 2387 + Report = 4, // RFC 6522 + Signed = 5, // RFC 1847, section 2.1 + Encrypted = 6 // RFC 1847, section 2.2 + }; + + /* [0] --- */ + + /* [1] Constructors and Destructors */ + explicit MimeMultiPart(MultiPartType type = Related); + + /* [1] --- */ + + /* [2] Getters and Setters */ + + void setMimeType(MultiPartType type); + + [[nodiscard]] MultiPartType getMimeType() const; + + [[nodiscard]] const QList<MimePart *> &getParts() const; + + /* [2] --- */ + + /* [3] Public methods */ + + void addPart(MimePart *part); + + void prepare() override; + + /* [3] --- */ + +protected: + QList<MimePart *> parts; + + MultiPartType type; +}; + +#endif // MIMEMULTIPART_H diff --git a/src/smtp/mimepart.h b/src/smtp/mimepart.h new file mode 100644 index 00000000..1a1386de --- /dev/null +++ b/src/smtp/mimepart.h @@ -0,0 +1,110 @@ +/* + Copyright (c) 2011-2012 - Tőkés Attila + + This file is part of SmtpClient for Qt. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + See the LICENSE file for more details. +*/ + +#ifndef MIMEPART_H +#define MIMEPART_H + +#include "mimecontentformatter.h" +#include <QObject> + +#include "smtpexports.h" + +class SMTP_EXPORT MimePart : public QObject { +Q_OBJECT +public: + /* [0] Enumerations */ + enum Encoding { + _7Bit, _8Bit, Base64, QuotedPrintable + }; + + /* [0] --- */ + + /* [1] Constructors and Destructors */ + + MimePart(); + + ~MimePart() = default; + + /* [1] --- */ + + /* [2] Getters and Setters */ + + [[nodiscard]] const QString &getHeader() const; + + [[nodiscard]] const QByteArray &getContent() const; + + void setContent(const QByteArray &content); + + void setHeader(const QString &header); + + void addHeaderLine(const QString &line); + + void setContentId(const QString &cId); + + [[nodiscard]] const QString &getContentId() const; + + void setContentName(const QString &cName); + + [[nodiscard]] const QString &getContentName() const; + + void setContentType(const QString &cType); + + [[nodiscard]] const QString &getContentType() const; + + void setCharset(const QString &charset); + + [[nodiscard]] const QString &getCharset() const; + + void setEncoding(Encoding enc); + + [[nodiscard]] Encoding getEncoding() const; + + MimeContentFormatter &getContentFormatter(); + + /* [2] --- */ + + /* [3] Public methods */ + + virtual QString toString(); + + virtual void prepare(); + + /* [3] --- */ + +protected: + /* [4] Protected members */ + + QString header; + QByteArray content; + + QString cId; + QString cName; + QString cType; + QString cCharset; + QString cBoundary; + Encoding cEncoding; + + QString mimeString; + bool prepared; + + MimeContentFormatter formatter; + + /* [4] --- */ +}; + +#endif // MIMEPART_H diff --git a/src/smtp/mimetext.h b/src/smtp/mimetext.h new file mode 100644 index 00000000..c21a1c5e --- /dev/null +++ b/src/smtp/mimetext.h @@ -0,0 +1,62 @@ +/* + Copyright (c) 2011-2012 - Tőkés Attila + + This file is part of SmtpClient for Qt. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + See the LICENSE file for more details. +*/ + +#ifndef MIMETEXT_H +#define MIMETEXT_H + +#include "mimepart.h" + +#include "smtpexports.h" + +class SMTP_EXPORT MimeText : public MimePart { +public: + + /* [1] Constructors and Destructors */ + + explicit MimeText(const QString &text = ""); + + ~MimeText() override; + + /* [1] --- */ + + + /* [2] Getters and Setters*/ + + void setText(const QString &text); + + [[nodiscard]] const QString &getText() const; + + /* [2] --- */ + +protected: + + /* [3] Protected members */ + + QString text; + /* [3] --- */ + + + /* [4] Protected methods */ + + void prepare() override; + + /* [4] --- */ + +}; + +#endif // MIMETEXT_H diff --git a/src/smtp/quotedprintable.h b/src/smtp/quotedprintable.h new file mode 100644 index 00000000..00ca3cf8 --- /dev/null +++ b/src/smtp/quotedprintable.h @@ -0,0 +1,39 @@ +/* + Copyright (c) 2011-2012 - Tőkés Attila + + This file is part of SmtpClient for Qt. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + See the LICENSE file for more details. +*/ + +#ifndef QUOTEDPRINTABLE_H +#define QUOTEDPRINTABLE_H + +#include <QObject> +#include <QByteArray> + +#include "smtpexports.h" + +class SMTP_EXPORT QuotedPrintable : public QObject { +Q_OBJECT +public: + + static QString encode(const QByteArray &input); + + static QByteArray decode(const QString &input); + +private: + QuotedPrintable(); +}; + +#endif // QUOTEDPRINTABLE_H diff --git a/src/smtp/smtpclient.h b/src/smtp/smtpclient.h new file mode 100644 index 00000000..29c507dc --- /dev/null +++ b/src/smtp/smtpclient.h @@ -0,0 +1,197 @@ +/* + Copyright (c) 2011-2012 - Tőkés Attila + + This file is part of SmtpClient for Qt. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + See the LICENSE file for more details. +*/ + +#ifndef SMTPCLIENT_H +#define SMTPCLIENT_H + +#include <QObject> +#include <QtNetwork/QSslSocket> + +#include "mimemessage.h" +#include "smtpexports.h" + +class SMTP_EXPORT SmtpClient : public QObject { +Q_OBJECT +public: + + /* [0] Enumerations */ + + enum AuthMethod { + AuthPlain, + AuthLogin + }; + + enum SmtpError { + ConnectionTimeoutError, + ResponseTimeoutError, + SendDataTimeoutError, + AuthenticationFailedError, + ServerError, // 4xx smtp error + ClientError // 5xx smtp error + }; + + enum ConnectionType { + TcpConnection, + SslConnection, + TlsConnection // STARTTLS + }; + + /* [0] --- */ + + + /* [1] Constructors and Destructors */ + + explicit SmtpClient(const QString &host = "localhost", int port = 25, ConnectionType ct = TcpConnection); + + ~SmtpClient() override; + + /* [1] --- */ + + + /* [2] Getters and Setters */ + + [[nodiscard]] const QString &getHost() const; + + void setHost(const QString &host); + + [[nodiscard]] int getPort() const; + + void setPort(int port); + + [[nodiscard]] const QString &getName() const; + + void setName(const QString &name); + + [[nodiscard]] ConnectionType getConnectionType() const; + + void setConnectionType(ConnectionType ct); + + [[nodiscard]] const QString &getUser() const; + + void setUser(const QString &user); + + [[nodiscard]] const QString &getPassword() const; + + void setPassword(const QString &password); + + [[nodiscard]] SmtpClient::AuthMethod getAuthMethod() const; + + void setAuthMethod(AuthMethod method); + + [[nodiscard]] const QString &getResponseText() const; + + [[nodiscard]] int getResponseCode() const; + + [[nodiscard]] int getConnectionTimeout() const; + + void setConnectionTimeout(int msec); + + [[nodiscard]] int getResponseTimeout() const; + + void setResponseTimeout(int msec); + + [[nodiscard]] int getSendMessageTimeout() const; + + void setSendMessageTimeout(int msec); + + QTcpSocket *getSocket(); + + + /* [2] --- */ + + + /* [3] Public methods */ + + bool connectToHost(); + + bool login(); + + bool login(const QString &user, const QString &password, AuthMethod method = AuthLogin); + + bool sendMail(MimeMessage &email); + + void quit(); + + + /* [3] --- */ + +protected: + + /* [4] Protected members */ + + QTcpSocket *socket; + + QString host; + int port; + ConnectionType connectionType; + QString name; + + QString user; + QString password; + AuthMethod authMethod; + + int connectionTimeout; + int responseTimeout; + int sendMessageTimeout; + + + QString responseText; + int responseCode; + + + class ResponseTimeoutException : public std::exception { + }; + + class SendMessageTimeoutException : public std::exception { + }; + + /* [4] --- */ + + + /* [5] Protected methods */ + + void waitForResponse(); + + void sendMessage(const QString &text); + + /* [5] --- */ + +protected slots: + + /* [6] Protected slots */ + + void socketStateChanged(QAbstractSocket::SocketState state); + + void socketError(QAbstractSocket::SocketError error); + + void socketReadyRead(); + + /* [6] --- */ + + +signals: + + /* [7] Signals */ + + void smtpError(SmtpClient::SmtpError e); + + /* [7] --- */ + +}; + +#endif // SMTPCLIENT_H diff --git a/src/smtp/smtpexports.h b/src/smtp/smtpexports.h new file mode 100644 index 00000000..9ca12bae --- /dev/null +++ b/src/smtp/smtpexports.h @@ -0,0 +1,10 @@ +#ifndef SMTPEXPORTS_H
+#define SMTPEXPORTS_H
+
+#ifdef SMTP_BUILD
+#define SMTP_EXPORT
+#else
+#define SMTP_EXPORT
+#endif
+
+#endif // SMTPEXPORTS_H
|