Subject: RE: Lotus C API - accented chars display incorrectly in subject and message body
I read somewhere that the Lotus Notes API does not support passing some foreign characters or Extended ASCII characters. I’m not sure whether this is true or not. In any case, this is a excerpt from the relevant section of the code. It’s probably more or less the same as the SendMail program in the Samples folder. Thanks.
LPSTR szSubject = NULL;
LPSTR szAttachments = NULL;
LPSTR szBody = NULL;
…
STATUS LNPUBLIC SendMail()
{
STATUS error = NOERROR; /* returned ERR_SENDMAIL_... value */
char szMailServerName[MAXUSERNAME + 1];
char szMailFileName[MAXUSERNAME + 1];
char szMailFilePath[MAXPATH + 1];
char szMailBoxPath[MAXPATH + 1];
WORD wRecipientsSize;
WORD wSendToSize;
WORD wRecipientsCount = 0;
WORD wSendToCount = 0;
LIST *plistRecipients;
LIST *plistSendTo;
char *szNextName; /* used when parsing szSendTo, etc. */
DWORD dwBodyItemLen;
DBHANDLE hOrigDB;
NOTEID OrigNoteID;
OID OrigNoteOID;
OID NewNoteOID;
/* Read the "MailServer" entry from NOTES.INI */
if (!OSGetEnvironmentString(MAIL_MAILSERVER_ITEM, szMailServerName, MAXUSERNAME))
{
return ERR_SENDMAIL_SERVERNAME;
}
/* Read the "MailFile" entry from NOTES.INI */
if (!OSGetEnvironmentString(MAIL_MAILFILE_ITEM, szMailFileName, MAXUSERNAME))
{
return ERR_SENDMAIL_MAILFILENAME;
}
/* Try to open the user's mail file on the mail server */
OSPathNetConstruct(NULL, szMailServerName, szMailFileName, szMailFilePath);
status = MailOpenMessageFile(szMailFilePath, &hMailFile);
if ((ERR(status) == ERR_NO_NETBIOS) || (ERR(status) == ERR_SERVER_NOT_RESPONDING))
{
return ERR_SENDMAIL_CANTOPENMAILFILE;
}
else if (status != NOERROR)
{
return ERR_SENDMAIL_CANTOPENMAILFILE;
}
/* Create a new Mail Memo */
if (status = MailCreateMessage(hMailFile, &hMsg))
{
/* Unable to create Memo */
return CloseFile(ERR_SENDMAIL_CANTCREATEMEMO);
}
/* Allocate lists for recipients */
if (status = ListAllocate(0, 0, TRUE, &hRecipientsList, &plistRecipients, &wRecipientsSize))
{
/* Unable to allocate Lists */
return CloseMsg(ERR_SENDMAIL_CANTALLOCATELIST);
}
OSUnlockObject(hRecipientsList);
if (status = ListAllocate(0, 0, TRUE, &hSendToList, &plistSendTo, &wSendToSize))
{
/* Unable to allocate SendTo List */
return CloseMsg(ERR_SENDMAIL_CANTALLOCATELIST);
}
OSUnlockObject(hSendToList);
/* Parse SendTo string. Add names to SendTo and Recipients lists. */
szNextName = strtok(szSendTo, ";");
while (szNextName != NULL)
{
while (isspace(*szNextName)) /* Skip white space before name */
{
szNextName++;
}
if (status = ListAddEntry(hSendToList, TRUE, &wSendToSize, wSendToCount++, szNextName, (WORD)lstrlen(szNextName)))
{
/* Unable to add name to SendTo list */
return CloseMsg(ERR_SENDMAIL_CANTADDTOSENDLIST);
}
if (status = ListAddEntry(hRecipientsList, TRUE, &wRecipientsSize, wRecipientsCount++, szNextName, (WORD)lstrlen(szNextName)))
{
/* Unable to add name to Recipients List */
return CloseMsg(ERR_SENDMAIL_CANTADDTORECIPLIST);
}
szNextName = strtok(NULL, ";");
}
/* Add the Recipients item to the message. */
if (wRecipientsCount == 0)
{
/* Mail memo has no recipients. */
return CloseMsg(ERR_SENDMAIL_NORECIPIENTS);
}
if (status = MailAddRecipientsItem(hMsg, hRecipientsList, wRecipientsSize))
{
/* Unable to set Recipient item in memo */
return CloseMsg(ERR_SENDMAIL_CANTSETRECIPIENT);
}
hRecipientsList = NULLHANDLE;
/* Add the SendTo items to the message. */
if (status = MailAddHeaderItemByHandle(hMsg, MAIL_SENDTO_ITEM_NUM, hSendToList, wSendToSize, 0))
{
/* Unable to set SendTo item in memo */
return CloseMsg(ERR_SENDMAIL_CANTSETSENDTO);
}
hSendToList = NULLHANDLE;
/* Add the Form item to the message */
if (status = MailAddHeaderItem(hMsg, MAIL_FORM_ITEM_NUM, MAIL_MEMO_FORM, (WORD)lstrlen(MAIL_MEMO_FORM)))
{
/* Unable to set Form item in memo */
return CloseMsg(ERR_SENDMAIL_CANTSETFORM);
}
/* Add From, Subject, Delivery Priority, & etc. items to the message */
if (status = MailAddHeaderItem(hMsg, MAIL_FROM_ITEM_NUM, szFrom, (WORD)lstrlen(szFrom)))
{
/* Unable to set From item in memo */
return CloseMsg(ERR_SENDMAIL_CANTSETFROM);
}
if (status = MailAddHeaderItem(hMsg, MAIL_SUBJECT_ITEM_NUM, szSubject, (WORD)lstrlen(szSubject)))
{
/* Unable to set Subject item in memo */
return CloseMsg(ERR_SENDMAIL_CANTSETSUBJECT);
}
/* Set Delivery Priority to "N"ormal */
if (error = MailAddHeaderItem(hMsg, MAIL_DELIVERYPRIORITY_ITEM_NUM, "N", (WORD)1))
{
/* Unable to set Delivery Priority item in memo */
return CloseMsg(ERR_SENDMAIL_CANTSETPRIORITY);
}
/* Set Delivery Report to "B"asic */
if (error = MailAddHeaderItem(hMsg, MAIL_DELIVERYREPORT_ITEM_NUM, "B", (WORD)1))
{
/* Unable to set Delivery Report into memo */
return CloseMsg(ERR_SENDMAIL_CANTSETREPT);
}
/* Set "ComposedDate" to tdDate = when dialog box was initialized */
if (status = MailAddHeaderItem(hMsg, MAIL_COMPOSEDDATE_ITEM_NUM, (BYTE*)(&tdDate), (WORD)sizeof(TIMEDATE)))
{
/* Unable to set Composed Date in memo */
return CloseMsg(ERR_SENDMAIL_CANTSETCOMPDATE);
}
if (status = MailCreateBodyItem(&hBodyItem, &dwBodyItemLen))
{
/* Unable to create body item in message */
hBodyItem = NULLHANDLE;
return CloseMsg(ERR_SENDMAIL_CANTCREATEBODY);
}
if (status = MailAppendBodyItemLine(hBodyItem, &dwBodyItemLen, szBody, wBodyLen))
{
/* Unable to append text to body */
return CloseMsg(ERR_SENDMAIL_CANTAPPENDBODYLINE);
}
if (status = MailAddBodyItem(hMsg, hBodyItem, dwBodyItemLen, NULL))
{
/* Unable to add Body item to memo */
return CloseMsg(ERR_SENDMAIL_CANTADDBODY);
}
/* Set "PostedDate" to the current time/date right now */
OSCurrentTIMEDATE(&tdDate);
if (status = MailAddHeaderItem(hMsg, MAIL_POSTEDDATE_ITEM_NUM, (BYTE*)(&tdDate), (WORD)sizeof(TIMEDATE)))
{
return CloseMsg(ERR_SENDMAIL_CANTSETPOSTDATE);
}
/* Attachments are processed here */
nAttCount = 0;
if (bHasAttachment)
{
szNextName = strtok(szAttachments, ";,");
while (szNextName != NULL)
{
szSourceName[nAttCount] = (char *)malloc(sizeof(char) * strlen(szNextName) + 1);
strcpy(szSourceName[nAttCount], szNextName);
szNextName = strtok(NULL, ";,");
szAttachName[nAttCount] = (char *)malloc(sizeof(char) * strlen(szNextName) + 1);
strcpy(szAttachName[nAttCount], szNextName);
MailAddMessageAttachment(hMsg, szSourceName[nAttCount], szAttachName[nAttCount]);
nAttCount++;
szNextName = strtok(NULL, ";,");
}
}
/* Deliver the message...
Open the router's MAIL.BOX on the mail server, then copy msg there.
*/
OSPathNetConstruct(NULL, szMailServerName, MAILBOX_NAME, szMailBoxPath);
if (status = NSFDbOpen(szMailBoxPath, &hMailBox))
{
/* Unable to open mailbox */
return CloseMsg(ERR_SENDMAIL_CANTOPENMAILBOX);
}
/* At this point, the message is simply a note in the user's mail file.
We now attempt to copy it to the user's mail box. This is how we do it:
- Save the message's DBID, NOTEID and OID.
- Set the DBID to the MAIL.BOX handle, NOTEID to 0, and the OID to a
newly generated OID associated with the MAIL.BOX
- Update the message (which stores it in the MAIL.BOX file)
- Finally, we restore the DBID, NOTEID and OID values.
*/
NSFNoteGetInfo(hMsg, _NOTE_ID, &OrigNoteID);
NSFNoteGetInfo(hMsg, _NOTE_DB, &hOrigDB);
NSFNoteGetInfo(hMsg, _NOTE_OID, &OrigNoteOID);
/* Set the message's OID database ID to match the mail box */
if (status = NSFDbGenerateOID (hMailBox, &NewNoteOID))
{
/* Unable to generate originator ID for mail box */
return CloseMsg(ERR_SENDMAIL_CANTGENOID);
}
NSFNoteSetInfo(hMsg, _NOTE_DB, &hMailBox);
NSFNoteSetInfo(hMsg, _NOTE_ID, 0);
NSFNoteSetInfo(hMsg, _NOTE_OID, &NewNoteOID);
/* Update message into MAIL.BOX on mail server. */
if (status = NSFNoteUpdate(hMsg, UPDATE_NOCOMMIT))
{
/* Unable to update message to router mail box */
return CloseMsg(ERR_SENDMAIL_CANTUPDATEBOX);
}
else /* Message successfully copied into router's mail box */
{
/* Restore msg to user's mail file and Update to save it there.*/
NSFNoteSetInfo(hMsg, _NOTE_DB, &hOrigDB);
NSFNoteSetInfo(hMsg, _NOTE_ID, &OrigNoteID);
NSFNoteSetInfo(hMsg, _NOTE_OID, &OrigNoteOID);
status = NSFNoteUpdate(hMsg, UPDATE_NOCOMMIT);
return CloseMsg(NOERROR);
}
}
Thanks.