/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program 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 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct ObMail = [ PMAIL_instance : PInstance, PMAIL_sKeyCode : S, PMAIL_sSmtpServer : S, PMAIL_iSmtpPort : I, PMAIL_sPhpUrl : S, PMAIL_sFrom : S, PMAIL_sTo : S, PMAIL_sSubject : S, PMAIL_sMessage : S, PMAIL_sAttachement : S, PMAIL_bUseSmtp : I ]mkObMail;; fun deleteOb(inst)= clearHttpRequest; clearHttpCookies; 0;; fun cbUrl(url, data, obstr)= if (obstr.PMAIL_bUseSmtp && ((strfindi "Mail Error" data 0) != nil)) then SendPluginEvent obstr.PMAIL_instance "Error" nil nil else if (!obstr.PMAIL_bUseSmtp && ((strfindi "Mail Ok" data 0) == nil)) then SendPluginEvent obstr.PMAIL_instance "Error" nil nil else SendPluginEvent obstr.PMAIL_instance "Success" nil nil; 0;; fun cbSendMail(inst, from, action, param, reply, obstr)= if ((obstr.PMAIL_sMessage == nil) || (obstr.PMAIL_sSubject == nil)) then nil else ( if (obstr.PMAIL_bUseSmtp) then ( //sendMail "smtp.free.fr" 25 "b.bourineau@i-maginer.com" "arkeon.work@gmail.com" nil "Test de mail" "Rhola le test ^^" ["test" "" "screenshots/mon_jan_26_12-20-54_2015.jpg"]::nil @cbUrl 0; let if (obstr.PMAIL_sAttachement != nil) then ["attachement" "" obstr.PMAIL_sAttachement]::nil else nil -> attachment in sendMail obstr.PMAIL_sSmtpServer obstr.PMAIL_iSmtpPort obstr.PMAIL_sFrom obstr.PMAIL_sTo nil obstr.PMAIL_sSubject obstr.PMAIL_sMessage attachment mkfun3 @cbUrl obstr; 0; ) else if (obstr.PMAIL_sPhpUrl != nil) then ( let getFileExt obstr.PMAIL_sAttachement -> ext in let getPathFile obstr.PMAIL_sAttachement "" -> [_ filename] in let if (!strcmpi ext "jpg") || (!strcmpi ext "jpeg") then "image/jpeg" else if (!strcmpi ext "png") then "image/png" else "text/plain" -> mimetype in let ["keycode" (_MD5value obstr.PMAIL_sKeyCode) nil]:: ["from" obstr.PMAIL_sFrom nil]:: ["to" obstr.PMAIL_sTo nil]:: ["subject" obstr.PMAIL_sSubject nil]:: ["message" obstr.PMAIL_sMessage nil]:: ["attachement" (base64_encode _getpack _checkpack obstr.PMAIL_sAttachement) nil]:: ["fileName" filename nil]:: ["fileType" mimetype nil]:: nil -> lp in postUrlMultiPart obstr.PMAIL_sPhpUrl lp mkfun3 @cbUrl obstr; //"http://www.openspace3d.com/os3dMailSender.php" 0; ) else ( addLogMessage "Mail plugIT not configured"; SendPluginEvent obstr.PMAIL_instance "Error" nil nil; ); //reset for next mail set obstr.PMAIL_sAttachement = nil; set obstr.PMAIL_sMessage = nil; set obstr.PMAIL_sSubject = nil; ); 0;; fun cbGetTo(inst, from, action, param, reply, obstr)= SendPluginEvent obstr.PMAIL_instance "Mail to" obstr.PMAIL_sTo nil; 0;; fun cbGetFrom(inst, from, action, param, reply, obstr)= SendPluginEvent obstr.PMAIL_instance "Mail from" obstr.PMAIL_sFrom nil; 0;; fun cbSetSubject(inst, from, action, param, reply, obstr)= set obstr.PMAIL_sSubject = param; 0;; fun cbSetTo(inst, from, action, param, reply, obstr)= set obstr.PMAIL_sTo = param; 0;; fun cbSetFrom(inst, from, action, param, reply, obstr)= set obstr.PMAIL_sFrom = param; 0;; fun cbSetMessage(inst, from, action, param, reply, obstr)= set obstr.PMAIL_sMessage = param; 0;; fun cbSetAttachement(inst, from, action, param, reply, obstr)= set obstr.PMAIL_sAttachement = param; 0;; fun cbSetSmtpServer(inst, from, action, param, reply, obstr)= set obstr.PMAIL_sSmtpServer = param; 0;; fun cbSetSmtpPort(inst, from, action, param, reply, obstr)= let if param == nil then 25 else atoi param -> port in set obstr.PMAIL_iSmtpPort = port; 0;; fun newOb(inst)= let (getPluginInstanceParam inst "keycode") -> keycode in let (getPluginInstanceParam inst "smtp") -> smtp in let atoi (getPluginInstanceParam inst "smtpport") -> smtpport in let if (smtpport == nil) then 25 else smtpport -> smtpport in let (getPluginInstanceParam inst "phpurl") -> phpurl in let if ((phpurl == nil) || (!strcmp phpurl "")) then nil else if strIsUrl phpurl then phpurl else strcat "http://" phpurl -> phpurl in let atoi (getPluginInstanceParam inst "usesmtp") -> usesmtp in let if (usesmtp == nil) && (smtp != nil) then 1 else usesmtp -> usesmtp in let (getPluginInstanceParam inst "from") -> from in let (getPluginInstanceParam inst "to") -> to in let mkObMail [inst keycode smtp smtpport phpurl from to nil nil nil usesmtp] -> obstr in ( PluginRegisterAction inst "Get mail to" mkfun6 @cbGetTo obstr; PluginRegisterAction inst "Get mail from" mkfun6 @cbGetFrom obstr; PluginRegisterAction inst "Set subject" mkfun6 @cbSetSubject obstr; PluginRegisterAction inst "Set mail to" mkfun6 @cbSetTo obstr; PluginRegisterAction inst "Set mail from" mkfun6 @cbSetFrom obstr; PluginRegisterAction inst "Set message" mkfun6 @cbSetMessage obstr; PluginRegisterAction inst "Set attachement" mkfun6 @cbSetAttachement obstr; PluginRegisterAction inst "Set SMTP server" mkfun6 @cbSetSmtpServer obstr; PluginRegisterAction inst "Set SMTP port" mkfun6 @cbSetSmtpPort obstr; PluginRegisterAction inst "Send" mkfun6 @cbSendMail obstr; setPluginInstanceCbDel inst @deleteOb; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;