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");
|
||||||
@ -251,7 +252,28 @@ DeviceManager::DeviceSetupStatus DevicePluginMailNotification::setupDevice(Devic
|
|||||||
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);
|
||||||
@ -320,7 +342,6 @@ DeviceManager::DeviceError DevicePluginMailNotification::executeAction(Device *d
|
|||||||
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;
|
||||||
@ -341,8 +362,10 @@ void DevicePluginMailNotification::testLoginFinished(const bool &success)
|
|||||||
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess);
|
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess);
|
||||||
} else {
|
} else {
|
||||||
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure);
|
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure);
|
||||||
|
if(m_clients.contains(smtpClient)) {
|
||||||
m_clients.remove(smtpClient);
|
m_clients.remove(smtpClient);
|
||||||
delete smtpClient;
|
}
|
||||||
|
smtpClient->deleteLater();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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",
|
||||||
|
|||||||
@ -164,14 +164,17 @@ void SmtpClient::readData()
|
|||||||
} else {
|
} else {
|
||||||
m_state = TestLoginFinishedState;
|
m_state = TestLoginFinishedState;
|
||||||
}
|
}
|
||||||
break; }
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case TestLoginFinishedState:
|
case TestLoginFinishedState:
|
||||||
if(responseLine == "235") {
|
if(responseLine == "235") {
|
||||||
emit testLoginFinished(true);
|
emit testLoginFinished(true);
|
||||||
|
} else {
|
||||||
|
emit testLoginFinished(false);
|
||||||
|
}
|
||||||
m_socket->close();
|
m_socket->close();
|
||||||
m_testLogin = false;
|
m_testLogin = false;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case MailState:
|
case MailState:
|
||||||
if(responseLine == "235") {
|
if(responseLine == "235") {
|
||||||
|
|||||||
Reference in New Issue
Block a user