Poco Script FAQ - Updating an Address Book from a Script

Poco Script FAQ - Updating an Address Book from a Script

Q: Can I update an address book from a script?
 
A: Yes, under Poco 2.1 it was quite complex, especially if you want to check for duplicate names (see Historical method below). With release 2.5 of Poco Slaven has added a number of commands to allow scripts to manipulate address books:
AddAddress
Adds an address of the form "Name <address>" to an address book.
AddRawAddress
Adds address stored in a multi-line variable to an address book.
GetRawAddress
Retrieves information for an address from an address book.
IsAddressPresent
Determines if an address is present in an address book.
RemoveAddress
Deletes an address from an address book.

Historical method

You should also be aware of the following experience I had:

I thought I'd post some comments regarding a recent problem I've been investigating. I wrote a script for someone that automatically examines incoming messages, extracts certain information and examines an address book to see if an entry for the person is already there. In cases where no entry is present the script adds an entry. The person reported that the entries were not always showing up. I investigated this for a couple of weeks but could not reproduce the problem until last night. I had been looking for bugs in the script but the debug code I put in, including a post-add check of the address book, revealed that the script was operating correctly.

I finally had a clue, if the script was updating the address book but the changes were not evident to the user then some action must be taking place that caused Poco to re-write the copy of the address book it had in memory to disk before the address book could be refreshed.

Investigation revealed that there are a number of possible ways that Poco might update an address book (this list may be incomplete):