Using API copy a Item from one note to another

Hello,

I would like to copy the “SendTo” field from one note to another using the c notes api. This field can be either a TEXT type field for a single address or can be a TEXT LIST type field if more than one address is specified.

What is the best approach to copy this field from one note to another?

Thank you

Subject: here is one solution I came up with

I would have rather just used the NSFItemCopy() function but I kept getting invalid handle, handle out of range errors when using this after NSFItemInfo(). According to NSFItemCopy() the BLOCKID should be the header which is the one I used but still kept getting errors. So I settled for this approach. Basically using NSFGetItemText() of a Text List field will give all results but separated by a comma and space. So it checks for how many commas there are and stores this in count. Then if count equals 1 we know we can use the MailAddHeaderItem() function, and if more than 1 we then use NSFItemAppendTextList() function because it is a list of multiple items. I still have one concern, I am setting field_text length to max of 4096 and I am not sure what the max length could be. But this works.

WORD field_len;

char field_text[4096];

int count, i;

char * pSendTo;

field_len = NSFItemGetText(note_handle, “SendTo”, field_text, sizeof (field_text));

field_text[field_len] = ‘\0’;

NSFNoteClose(note_handle);

if(field_len == 0)

{

NSFNoteClose(note_handle);

error=SENDMAILERROR;

goto CloseFile;

}

count=1;

for(i=0; i<field_len; i++)

{

if(field_text[i] == ‘;’)

  count++;

}

if(count == 1)

{

if (status = MailAddHeaderItem( hMsg, MAIL_SENDTO_ITEM_NUM, field_text, (WORD)field_len))

{

  OSLoadString( NULLHANDLE, status, szString, sizeof(szString)-1);

  LogAddText(LOG_EVENT_ENTRY_NO_TIMESTAMP, LOG_TO_CONSOLE|LOG_AUTO_ROLLOVER, 

             LOG_ITEM_EVENTS, NULL, NOERROR, szString);

  error=SENDMAILERROR;

  goto CloseMsg;

}

if (status = MailAddHeaderItem( hMsg, MAIL_RECIPIENTS_ITEM_NUM, field_text, (WORD)field_len))

{

  OSLoadString( NULLHANDLE, status, szString, sizeof(szString)-1);

  LogAddText(LOG_EVENT_ENTRY_NO_TIMESTAMP, LOG_TO_CONSOLE|LOG_AUTO_ROLLOVER, 

             LOG_ITEM_EVENTS, NULL, NOERROR, szString);

  error=SENDMAILERROR;

  goto CloseMsg;

}

}

else

{

pSendTo = &field_text[0];

for(i=0; i <= field_len; i++)

{

  if(field_text[i] == ';')

  {

     field_text[i] = '\0';



     if (status = NSFItemAppendTextList(hMsg, "SendTo", pSendTo, (WORD) strlen(pSendTo), FALSE))

     {

        OSLoadString( NULLHANDLE, status, szString, sizeof(szString)-1);

        LogAddText(LOG_EVENT_ENTRY_NO_TIMESTAMP, LOG_TO_CONSOLE|LOG_AUTO_ROLLOVER, 

                   LOG_ITEM_EVENTS, NULL, NOERROR, szString);

        error=SENDMAILERROR;

        goto CloseMsg;

     }



     if (status = NSFItemAppendTextList(hMsg, "Recipients", pSendTo, (WORD) strlen(pSendTo), FALSE))

     {

        OSLoadString( NULLHANDLE, status, szString, sizeof(szString)-1);

        LogAddText(LOG_EVENT_ENTRY_NO_TIMESTAMP, LOG_TO_CONSOLE|LOG_AUTO_ROLLOVER, 

                   LOG_ITEM_EVENTS, NULL, NOERROR, szString);

        error=SENDMAILERROR;

        goto CloseMsg;

     }



     pSendTo = &field_text[i];

     pSendTo++; //go past the \0

     pSendTo++; //go past the space

  }

  else if (field_text[i] == '\0')

  {

     if (status = NSFItemAppendTextList(hMsg, "SendTo", pSendTo, (WORD) strlen(pSendTo), FALSE))

     {

        OSLoadString( NULLHANDLE, status, szString, sizeof(szString)-1);

        LogAddText(LOG_EVENT_ENTRY_NO_TIMESTAMP, LOG_TO_CONSOLE|LOG_AUTO_ROLLOVER, 

                   LOG_ITEM_EVENTS, NULL, NOERROR, szString);

        error=SENDMAILERROR;

        goto CloseMsg;

     }



     if (status = NSFItemAppendTextList(hMsg, "Recipients", pSendTo, (WORD) strlen(pSendTo), FALSE))

     {

        OSLoadString( NULLHANDLE, status, szString, sizeof(szString)-1);

        LogAddText(LOG_EVENT_ENTRY_NO_TIMESTAMP, LOG_TO_CONSOLE|LOG_AUTO_ROLLOVER, 

                   LOG_ITEM_EVENTS, NULL, NOERROR, szString);

        error=SENDMAILERROR;

        goto CloseMsg;

     }

  }

}

}