7- Application Service : exemple du Mail |
![]() ![]() ![]() |
![]() <xul:toolbar>
<xul:commands>
|
La commande XUL nsCmd:MailSendMsg
permet
de d'appeler la fonction approprié en javascript SendMailMessage() function SendMailMessage()
|
L'appel de SendMailMessage()
instancie un objet dans MailAppCore et prend les données
à partir du formulaire suivant :
![]() |
<form ENCTYPE="text/plain" onSubmit="return submitForms()">
<TABLE bgcolor="#C0C0C0"> <TR> <TD> <fieldset width="100%" height="100%" > <legend align=left> Info </legend> <TABLE width="100%" height="100%"> <TR> <TD>Address:</TD> <TD width="100%"><input type="text" name="addrTo"></TD> </TR> <TR> <TD>Subject:</TD> <TD><input type="text" name="subject" id="subject"></TD> </TR> </TABLE> </fieldset> </TD> </TR> <TR> <TD> <fieldset width="100%" height="100%" > <legend align=left> Message </legend> <TEXTAREA cols=40 rows=15 name="mailbody"></TEXTAREA> </fieldset> </TD> </TR></TABLE></form> |
Le code de MailAppCore est en C++
NS_IMETHODIMP
nsMailCore::SendMail(const nsString& aAddrTo, const nsString& aSubject, const
nsString& aMsg)
{
if (nsnull == mScriptContext) {
return NS_ERROR_FAILURE;
}
printf("----------------------------\n");
printf("-- Sending Mail Message\n");
printf("----------------------------\n");
printf("To: %s \nSub: %s \nMsg: %s\n", aAddrTo.ToNewCString(),
&nb sp; aSubject.ToNewCString(),
&nb sp; aMsg.ToNewCString()); // these
ToNewCString's leak
printf("----------------------------\n");if (nsnull != mScriptContext) {
const char* url = "";
PRBool isUndefined = PR_FALSE;
nsString rVal;
mScriptContext->EvaluateString(mScript, url, 0, rVal, &isUndefined);
}
return NS_OK;
}
![]() |