added yahoo mail notification
This commit is contained in:
parent
be6d676fdf
commit
f35f136a4c
@ -64,6 +64,8 @@ public:
|
|||||||
DeviceErrorSetupMethodNotSupported,
|
DeviceErrorSetupMethodNotSupported,
|
||||||
DeviceErrorHardwareNotAvailable,
|
DeviceErrorHardwareNotAvailable,
|
||||||
DeviceErrorHardwareFailure,
|
DeviceErrorHardwareFailure,
|
||||||
|
// TODO: Bump API version
|
||||||
|
//DeviceErrorAuthentificationFailure,
|
||||||
DeviceErrorAsync,
|
DeviceErrorAsync,
|
||||||
DeviceErrorDeviceInUse,
|
DeviceErrorDeviceInUse,
|
||||||
DeviceErrorPairingTransactionIdNotFound,
|
DeviceErrorPairingTransactionIdNotFound,
|
||||||
|
|||||||
@ -230,6 +230,7 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
DeviceClassId googleMailDeviceClassId = DeviceClassId("3869884a-1592-4b8f-84a7-994be18ff555");
|
DeviceClassId googleMailDeviceClassId = DeviceClassId("3869884a-1592-4b8f-84a7-994be18ff555");
|
||||||
|
DeviceClassId yahooMailDeviceClassId = DeviceClassId("59409e8f-0c83-414f-abd5-bbbf2758acba");
|
||||||
DeviceClassId customMailDeviceClassId = DeviceClassId("f4844c97-7ca6-4349-904e-ff9749a9fe74");
|
DeviceClassId customMailDeviceClassId = DeviceClassId("f4844c97-7ca6-4349-904e-ff9749a9fe74");
|
||||||
|
|
||||||
ActionTypeId sendMailActionTypeId = ActionTypeId("054613b0-3666-4dad-9252-e0ebca187edc");
|
ActionTypeId sendMailActionTypeId = ActionTypeId("054613b0-3666-4dad-9252-e0ebca187edc");
|
||||||
@ -245,13 +246,34 @@ DevicePluginMailNotification::~DevicePluginMailNotification()
|
|||||||
DeviceManager::DeviceSetupStatus DevicePluginMailNotification::setupDevice(Device *device)
|
DeviceManager::DeviceSetupStatus DevicePluginMailNotification::setupDevice(Device *device)
|
||||||
{
|
{
|
||||||
// Google mail
|
// Google mail
|
||||||
if(device->deviceClassId() == googleMailDeviceClassId){
|
if(device->deviceClassId() == googleMailDeviceClassId) {
|
||||||
device->setName("Google Mail (" + device->paramValue("user").toString() + ")");
|
device->setName("Google Mail (" + device->paramValue("user").toString() + ")");
|
||||||
SmtpClient *smtpClient = new SmtpClient(this);
|
SmtpClient *smtpClient = new SmtpClient(this);
|
||||||
smtpClient->setHost("smtp.gmail.com");
|
smtpClient->setHost("smtp.gmail.com");
|
||||||
smtpClient->setPort(465);
|
smtpClient->setPort(465);
|
||||||
smtpClient->setUser(device->paramValue("user").toString());
|
smtpClient->setUser(device->paramValue("user").toString());
|
||||||
|
// TODO: use cryptography to save password not as plain text
|
||||||
|
smtpClient->setPassword(device->paramValue("password").toString());
|
||||||
|
smtpClient->setAuthMethod(SmtpClient::AuthMethodLogin);
|
||||||
|
smtpClient->setEncryptionType(SmtpClient::EncryptionTypeSSL);
|
||||||
|
smtpClient->setSender(device->paramValue("user").toString());
|
||||||
|
smtpClient->setRecipient(device->paramValue("recipient").toString());
|
||||||
|
|
||||||
|
connect(smtpClient, &SmtpClient::testLoginFinished, this, &DevicePluginMailNotification::testLoginFinished);
|
||||||
|
connect(smtpClient, &SmtpClient::sendMailFinished, this, &DevicePluginMailNotification::sendMailFinished);
|
||||||
|
m_clients.insert(smtpClient,device);
|
||||||
|
|
||||||
|
smtpClient->testLogin();
|
||||||
|
|
||||||
|
return DeviceManager::DeviceSetupStatusAsync;
|
||||||
|
}
|
||||||
|
// Yahoo mail
|
||||||
|
if(device->deviceClassId() == yahooMailDeviceClassId) {
|
||||||
|
device->setName("Yahoo Mail (" + device->paramValue("user").toString() + ")");
|
||||||
|
SmtpClient *smtpClient = new SmtpClient(this);
|
||||||
|
smtpClient->setHost("smtp.mail.yahoo.com");
|
||||||
|
smtpClient->setPort(465);
|
||||||
|
smtpClient->setUser(device->paramValue("user").toString());
|
||||||
// TODO: use cryptography to save password not as plain text
|
// TODO: use cryptography to save password not as plain text
|
||||||
smtpClient->setPassword(device->paramValue("password").toString());
|
smtpClient->setPassword(device->paramValue("password").toString());
|
||||||
smtpClient->setAuthMethod(SmtpClient::AuthMethodLogin);
|
smtpClient->setAuthMethod(SmtpClient::AuthMethodLogin);
|
||||||
@ -268,7 +290,7 @@ DeviceManager::DeviceSetupStatus DevicePluginMailNotification::setupDevice(Devic
|
|||||||
return DeviceManager::DeviceSetupStatusAsync;
|
return DeviceManager::DeviceSetupStatusAsync;
|
||||||
}
|
}
|
||||||
// Custom mail
|
// Custom mail
|
||||||
if(device->deviceClassId() == customMailDeviceClassId){
|
if(device->deviceClassId() == customMailDeviceClassId) {
|
||||||
device->setName("Custom Mail (" + device->paramValue("sender mail").toString() + ")");
|
device->setName("Custom Mail (" + device->paramValue("sender mail").toString() + ")");
|
||||||
SmtpClient *smtpClient = new SmtpClient(this);
|
SmtpClient *smtpClient = new SmtpClient(this);
|
||||||
smtpClient->setHost(device->paramValue("SMTP server").toString());
|
smtpClient->setHost(device->paramValue("SMTP server").toString());
|
||||||
@ -278,21 +300,21 @@ DeviceManager::DeviceSetupStatus DevicePluginMailNotification::setupDevice(Devic
|
|||||||
// TODO: use cryptography to save password not as plain text
|
// TODO: use cryptography to save password not as plain text
|
||||||
smtpClient->setPassword(device->paramValue("password").toString());
|
smtpClient->setPassword(device->paramValue("password").toString());
|
||||||
|
|
||||||
if(device->paramValue("authentification").toString() == "PLAIN"){
|
if(device->paramValue("authentification").toString() == "PLAIN") {
|
||||||
smtpClient->setAuthMethod(SmtpClient::AuthMethodPlain);
|
smtpClient->setAuthMethod(SmtpClient::AuthMethodPlain);
|
||||||
}else if(device->paramValue("authentification").toString() == "LOGIN"){
|
} else if(device->paramValue("authentification").toString() == "LOGIN") {
|
||||||
smtpClient->setAuthMethod(SmtpClient::AuthMethodLogin);
|
smtpClient->setAuthMethod(SmtpClient::AuthMethodLogin);
|
||||||
}else{
|
} else {
|
||||||
return DeviceManager::DeviceSetupStatusFailure;
|
return DeviceManager::DeviceSetupStatusFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(device->paramValue("encryption").toString() == "NONE"){
|
if(device->paramValue("encryption").toString() == "NONE") {
|
||||||
smtpClient->setEncryptionType(SmtpClient::EncryptionTypeNone);
|
smtpClient->setEncryptionType(SmtpClient::EncryptionTypeNone);
|
||||||
} else if(device->paramValue("encryption").toString() == "SSL"){
|
} else if(device->paramValue("encryption").toString() == "SSL") {
|
||||||
smtpClient->setEncryptionType(SmtpClient::EncryptionTypeSSL);
|
smtpClient->setEncryptionType(SmtpClient::EncryptionTypeSSL);
|
||||||
}else if(device->paramValue("encryption").toString() == "TLS"){
|
} else if(device->paramValue("encryption").toString() == "TLS") {
|
||||||
smtpClient->setEncryptionType(SmtpClient::EncryptionTypeTLS);
|
smtpClient->setEncryptionType(SmtpClient::EncryptionTypeTLS);
|
||||||
}else{
|
} else {
|
||||||
return DeviceManager::DeviceSetupStatusFailure;
|
return DeviceManager::DeviceSetupStatusFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,10 +339,9 @@ DeviceManager::HardwareResources DevicePluginMailNotification::requiredHardware(
|
|||||||
|
|
||||||
DeviceManager::DeviceError DevicePluginMailNotification::executeAction(Device *device, const Action &action)
|
DeviceManager::DeviceError DevicePluginMailNotification::executeAction(Device *device, const Action &action)
|
||||||
{
|
{
|
||||||
if(action.actionTypeId() == sendMailActionTypeId){
|
if(action.actionTypeId() == sendMailActionTypeId) {
|
||||||
SmtpClient *smtpClient= m_clients.key(device);
|
SmtpClient *smtpClient = m_clients.key(device);
|
||||||
smtpClient->sendMail(action.param("subject").value().toString(), action.param("body").value().toString(), action.id());
|
smtpClient->sendMail(action.param("subject").value().toString(), action.param("body").value().toString(), action.id());
|
||||||
|
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
}
|
}
|
||||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||||
@ -337,20 +358,22 @@ void DevicePluginMailNotification::testLoginFinished(const bool &success)
|
|||||||
{
|
{
|
||||||
SmtpClient *smtpClient = static_cast<SmtpClient*>(sender());
|
SmtpClient *smtpClient = static_cast<SmtpClient*>(sender());
|
||||||
Device *device = m_clients.value(smtpClient);
|
Device *device = m_clients.value(smtpClient);
|
||||||
if(success){
|
if(success) {
|
||||||
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess);
|
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess);
|
||||||
}else{
|
} else {
|
||||||
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure);
|
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure);
|
||||||
m_clients.remove(smtpClient);
|
if(m_clients.contains(smtpClient)) {
|
||||||
delete smtpClient;
|
m_clients.remove(smtpClient);
|
||||||
|
}
|
||||||
|
smtpClient->deleteLater();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginMailNotification::sendMailFinished(const bool &success, const ActionId &actionId)
|
void DevicePluginMailNotification::sendMailFinished(const bool &success, const ActionId &actionId)
|
||||||
{
|
{
|
||||||
if(success){
|
if(success) {
|
||||||
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorNoError);
|
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorNoError);
|
||||||
}else{
|
} else {
|
||||||
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorDeviceNotFound);
|
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorDeviceNotFound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,6 +41,41 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"deviceClassId": "59409e8f-0c83-414f-abd5-bbbf2758acba",
|
||||||
|
"name": "Yahoo Mail",
|
||||||
|
"createMethods": ["user"],
|
||||||
|
"paramTypes": [
|
||||||
|
{
|
||||||
|
"name": "user",
|
||||||
|
"type": "QString"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "password",
|
||||||
|
"type": "QString"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "recipient",
|
||||||
|
"type": "QString"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actionTypes": [
|
||||||
|
{
|
||||||
|
"id": "054613b0-3666-4dad-9252-e0ebca187edc",
|
||||||
|
"name": "Send mail",
|
||||||
|
"paramTypes": [
|
||||||
|
{
|
||||||
|
"name": "subject",
|
||||||
|
"type": "QString"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "body",
|
||||||
|
"type": "QString"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"deviceClassId": "f4844c97-7ca6-4349-904e-ff9749a9fe74",
|
"deviceClassId": "f4844c97-7ca6-4349-904e-ff9749a9fe74",
|
||||||
"name": "Custom Mail",
|
"name": "Custom Mail",
|
||||||
|
|||||||
@ -71,7 +71,7 @@ void SmtpClient::readData()
|
|||||||
QString response;
|
QString response;
|
||||||
QString responseLine;
|
QString responseLine;
|
||||||
|
|
||||||
while(m_socket->canReadLine() && responseLine[3] != ' '){
|
while(m_socket->canReadLine() && responseLine[3] != ' ') {
|
||||||
responseLine = m_socket->readLine();
|
responseLine = m_socket->readLine();
|
||||||
response.append(responseLine);
|
response.append(responseLine);
|
||||||
}
|
}
|
||||||
@ -79,32 +79,32 @@ void SmtpClient::readData()
|
|||||||
|
|
||||||
switch (m_state) {
|
switch (m_state) {
|
||||||
case InitState:
|
case InitState:
|
||||||
if(responseLine == "220"){
|
if(responseLine == "220") {
|
||||||
send("EHLO localhost");
|
send("EHLO localhost");
|
||||||
if(m_encryptionType == EncryptionTypeNone){
|
if(m_encryptionType == EncryptionTypeNone) {
|
||||||
m_state = AuthentificationState;
|
m_state = AuthentificationState;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(m_encryptionType == EncryptionTypeSSL){
|
if(m_encryptionType == EncryptionTypeSSL) {
|
||||||
m_state = HandShakeState;
|
m_state = HandShakeState;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(m_encryptionType == EncryptionTypeTLS){
|
if(m_encryptionType == EncryptionTypeTLS) {
|
||||||
m_state = StartTlsState;
|
m_state = StartTlsState;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case HandShakeState:
|
case HandShakeState:
|
||||||
if(responseLine == "250"){
|
if(responseLine == "250") {
|
||||||
if(!m_socket->isEncrypted() && m_encryptionType != EncryptionTypeNone){
|
if(!m_socket->isEncrypted() && m_encryptionType != EncryptionTypeNone) {
|
||||||
m_socket->startClientEncryption();
|
m_socket->startClientEncryption();
|
||||||
}
|
}
|
||||||
send("EHLO localhost");
|
send("EHLO localhost");
|
||||||
m_state = AuthentificationState;
|
m_state = AuthentificationState;
|
||||||
}
|
}
|
||||||
if(responseLine == "220"){
|
if(responseLine == "220") {
|
||||||
if(!m_socket->isEncrypted() && m_encryptionType != EncryptionTypeNone){
|
if(!m_socket->isEncrypted() && m_encryptionType != EncryptionTypeNone) {
|
||||||
m_socket->startClientEncryption();
|
m_socket->startClientEncryption();
|
||||||
}
|
}
|
||||||
send("EHLO localhost");
|
send("EHLO localhost");
|
||||||
@ -125,24 +125,24 @@ void SmtpClient::readData()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case StartTlsState:
|
case StartTlsState:
|
||||||
if(responseLine == "250"){
|
if(responseLine == "250") {
|
||||||
send("STARTTLS");
|
send("STARTTLS");
|
||||||
m_state = HandShakeState;
|
m_state = HandShakeState;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AuthentificationState:
|
case AuthentificationState:
|
||||||
if(responseLine == "250"){
|
if(responseLine == "250") {
|
||||||
if(m_authMethod == AuthMethodLogin){
|
if(m_authMethod == AuthMethodLogin) {
|
||||||
send("AUTH LOGIN");
|
send("AUTH LOGIN");
|
||||||
m_state = UserState;
|
m_state = UserState;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(m_authMethod == AuthMethodPlain){
|
if(m_authMethod == AuthMethodPlain) {
|
||||||
send("AUTH PLAIN " + QByteArray().append((char) 0).append(m_user).append((char) 0).append(m_password).toBase64());
|
send("AUTH PLAIN " + QByteArray().append((char) 0).append(m_user).append((char) 0).append(m_password).toBase64());
|
||||||
// if we just want to test the Login, we are almost done here
|
// if we just want to test the Login, we are almost done here
|
||||||
if(!m_testLogin){
|
if(!m_testLogin) {
|
||||||
m_state = MailState;
|
m_state = MailState;
|
||||||
}else{
|
} else {
|
||||||
m_state = TestLoginFinishedState;
|
m_state = TestLoginFinishedState;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -150,62 +150,65 @@ void SmtpClient::readData()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UserState:
|
case UserState:
|
||||||
if(responseLine == "334"){
|
if(responseLine == "334") {
|
||||||
send(QByteArray().append(m_user).toBase64());
|
send(QByteArray().append(m_user).toBase64());
|
||||||
m_state = PasswordState;
|
m_state = PasswordState;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PasswordState:
|
case PasswordState:
|
||||||
if(responseLine == "334"){
|
if(responseLine == "334") {
|
||||||
send(QByteArray().append(m_password).toBase64());
|
send(QByteArray().append(m_password).toBase64());
|
||||||
// if we just want to test the Login, we are almost done here
|
// if we just want to test the Login, we are almost done here
|
||||||
if(!m_testLogin){
|
if(!m_testLogin) {
|
||||||
m_state = MailState;
|
m_state = MailState;
|
||||||
}else{
|
} else {
|
||||||
m_state = TestLoginFinishedState;
|
m_state = TestLoginFinishedState;
|
||||||
}
|
}
|
||||||
break; }
|
break;
|
||||||
break;
|
|
||||||
case TestLoginFinishedState:
|
|
||||||
if(responseLine == "235"){
|
|
||||||
emit testLoginFinished(true);
|
|
||||||
m_socket->close();
|
|
||||||
m_testLogin = false;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case TestLoginFinishedState:
|
||||||
|
if(responseLine == "235") {
|
||||||
|
emit testLoginFinished(true);
|
||||||
|
} else {
|
||||||
|
emit testLoginFinished(false);
|
||||||
|
}
|
||||||
|
m_socket->close();
|
||||||
|
m_testLogin = false;
|
||||||
|
break;
|
||||||
case MailState:
|
case MailState:
|
||||||
if(responseLine == "235"){
|
if(responseLine == "235") {
|
||||||
send("MAIL FROM:<" + m_sender + ">");
|
send("MAIL FROM:<" + m_sender + ">");
|
||||||
m_state = RcptState;
|
m_state = RcptState;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RcptState:
|
case RcptState:
|
||||||
if(responseLine == "250"){
|
if(responseLine == "250") {
|
||||||
send("RCPT TO:<" + m_rcpt + ">");
|
send("RCPT TO:<" + m_rcpt + ">");
|
||||||
m_state = DataState;
|
m_state = DataState;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DataState:
|
case DataState:
|
||||||
if(responseLine == "250"){
|
if(responseLine == "250") {
|
||||||
send("DATA");
|
send("DATA");
|
||||||
m_state = BodyState;
|
m_state = BodyState;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BodyState:
|
case BodyState:
|
||||||
if(responseLine == "354"){
|
if(responseLine == "354") {
|
||||||
send(m_message + "\r\n.\r\n");
|
send(m_message + "\r\n.\r\n");
|
||||||
m_state = QuitState;
|
m_state = QuitState;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QuitState:
|
case QuitState:
|
||||||
if(responseLine == "250"){
|
if(responseLine == "250") {
|
||||||
emit sendMailFinished(true, m_actionId);
|
emit sendMailFinished(true, m_actionId);
|
||||||
send("QUIT");
|
send("QUIT");
|
||||||
m_state = CloseState;
|
m_state = CloseState;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CloseState:
|
case CloseState:
|
||||||
if(responseLine == "221"){
|
if(responseLine == "221") {
|
||||||
m_socket->close();
|
m_socket->close();
|
||||||
}
|
}
|
||||||
// some mail server does not recognize the QUIT command...so close the connection either way
|
// some mail server does not recognize the QUIT command...so close the connection either way
|
||||||
@ -213,7 +216,7 @@ void SmtpClient::readData()
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// unexpecterd response code received...
|
// unexpecterd response code received...
|
||||||
if(m_testLogin){
|
if(m_testLogin) {
|
||||||
emit testLoginFinished(false);
|
emit testLoginFinished(false);
|
||||||
m_testLogin = false;
|
m_testLogin = false;
|
||||||
m_socket->close();
|
m_socket->close();
|
||||||
|
|||||||
Reference in New Issue
Block a user