[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
Poco Forums • View topic - Show Recipients

Show Recipients

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Show Recipients

Postby Pete » Tue Nov 16, 2004 1:35 pm

This script will display a MessageBox with the list of all TO/CC/BCC addresses (including Full Names) for the currently selected message.

If the Full Name is not already part of an address, the script will try to obtain it from the user's address books. This is useful because:

  • Some messages do not have Full Names for each address (most often with incoming messages).
  • Pocomail (and probably Barca) don't keep the Full Names for BCC addresses.
  • It's useful if you don't normally view the headers in the preview pane.

I've added it to script button 9, so I can run it by clicking this button on the toolbar or by pressing Ctrl-9.
The MessageBox can be most easily closed by pressing the Escape key (or you can press the Enter key or of course click OK).

This script does not change the original message in any way.

There is a related script that puts an "M" in the index pane for messages that are addressed to multiple recipients:
http://pocosystems.com/forum/viewtopic.php?t=1270

Code: Select all
{  Script: Show Recipients.poc
{  Author: PJR
{ History: 15 Nov 2004 Initial Version
{          17 Nov 2004 (1) Always put Company Name (if it exists) at end
{                          of Full Name.
{                      (2) Made Nickname more important than Company Name
{                          in subroutine ADD_FULL_NAME.
{
{ This script will display a MessageBox to the user with the list of all
{ TO/CC/BCC addresses (including Full Names).
{
{ If the Full Name is not already part of an address, the script will
{ try to obtain it from the user's address books (see subroutines for
{ more comments about this).
{
{ This script does not change the original message in any way.

Set $OnErrorMessage ""
AddStrings $OnErrorMessage "Error in " $pocoScriptName
Set $OnErrorGoTo "POCO_ERROR"

Set $addressList ""
ReadHeader $FA_originalList "To:" %message
If $FA_originalList = "" Then READ_CC_HEADER
Set $FA_section " TO: "
Call FORMAT_ADDRESSES
AddStrings $addressList $FA_newList

:READ_CC_HEADER
ReadHeader $FA_originalList "CC:" %message
If $FA_originalList = "" Then READ_BCC_HEADER
Set $FA_section " CC: "
Call FORMAT_ADDRESSES
AddStrings $addressList "\n" $FA_newList

:READ_BCC_HEADER
ReadBCC $FA_originalList %message
If $FA_originalList = "" Then CHECK_FOR_NO_ADDRESSES
Set $FA_section "BCC: "
Call FORMAT_ADDRESSES
AddStrings $addressList "\n" $FA_newList

:CHECK_FOR_NO_ADDRESSES
If $addressList ! "" Then SHOW
Set $addressList "No addresses!"

:SHOW
MessageBox $addressList
Exit

:POCO_ERROR
Exit

{###############################################################################
{ SUBROUTINES
{###############################################################################

{*******************************************************************************
{ Format Addresses
{*******************************************************************************
{    Params:
{       $FA_section      (in)      (" TO: ", " CC: ", or "BCC: ")
{       $FA_originalList (in)
{       $FA_newList      (out)
{*******************************************************************************
{ This routine takes a multi-line list of email addresses of the form:
{    "John Doe" <john@abc.com>
{    John Doe <john@abc.com>
{    <john@abc.com>
{    john@abc.com
{    ...
{ and does the following for the MessageBox for the user:
{
{    1) Adds the Full Name (if possible) if it's not already part of the address.
{    2) Adds <...> around the email address if it doesn't already exist.
{    3) Adds "TO:" or "CC:" or "BCC:" to the first address in each section
{       or adds leading spaces to any other addresses in each section
{       so that everything is aligned vertically in the MessageBox for the user.
{*******************************************************************************
:FORMAT_ADDRESSES
Set $FA_newList ""
LineCount #FA_originalListSize $FA_originalList
Set #FA_i -1

:FA_LOOP
Inc #FA_i
If #FA_i = #FA_originalListSize Then Return
GetLine $FA_address #FA_i $FA_originalList
Trim $FA_address
StringPos #FA_index " " $FA_address
If #FA_index > 0 Then FA_FINISHED_ADDRESS
ExtractEmail $FA_address
IsAddressPresent &FA_present $FA_address "*"
Set $FA_tmp ""
AddStrings $FA_tmp "<" $FA_address ">"
Set $FA_address $FA_tmp
If &FA_present Then FA_GET_ADDRESS_BOOK_DATA
Goto FA_FINISHED_ADDRESS

:FA_GET_ADDRESS_BOOK_DATA
Set $AFN_address $FA_address
Call ADD_FULL_NAME
Set $FA_address $AFN_address

:FA_FINISHED_ADDRESS
AddStrings $FA_newList $FA_section $FA_address "\n"
Set $FA_section "     "
Goto FA_LOOP

{*******************************************************************************
{ Add Full Name
{*******************************************************************************
{    Param:
{       $AFN_address (in/out)
{*******************************************************************************
{ This routine tries to add missing address-book data to the address.
{
{ It will use the first populated set of fields from the address-book
{ that it finds, in this order:
{
{    1) Display-As (Company)
{    2) FirstName MiddleName LastName, Suffix (Company)
{    3) NickName (Company)
{    4) Company
{
{    (2) will only match if either FirstName or LastName is populated in
{    the address book.  If true, then every populated field in (2) will be added
{    to the address in the MessageBox.
{*******************************************************************************
:ADD_FULL_NAME
GetRawAddress $AFN_fieldList $AFN_address "*"
ReadCSV $AFN_fieldList $AFN_fieldList

{ get Company name now because it's used everywhere }
GetLine $AFN_company 15 $AFN_fieldList
Trim $AFN_company
Set $AFN_companyOriginal $AFN_company
If $AFN_company = "" Then AFN_CHECK_DISPLAY_AS
Set $AFN_tmp ""
AddStrings $AFN_tmp " (" $AFN_company ")"
Set $AFN_company $AFN_tmp

{1) DISPLAY-AS (Company)
:AFN_CHECK_DISPLAY_AS
GetLine $AFN_displayAs 1 $AFN_fieldList
Trim $AFN_displayAs
If $AFN_displayAs = "" Then AFN_CHECK_FIRST_NAME
Set $AFN_tmp ""
AddStrings $AFN_tmp "\"" $AFN_displayAs $AFN_company "\" " $AFN_address
Set $AFN_address $AFN_tmp
Return

{2) FIRSTNAME MIDDLENAME LASTNAME, SUFFIX (Company)
:AFN_CHECK_FIRST_NAME
Set $AFN_tmp "\""
GetLine $AFN_firstName 5 $AFN_fieldList
GetLine $AFN_middleName 6 $AFN_fieldList
Trim $AFN_firstName
Trim $AFN_middleName
If $AFN_firstName = "" Then AFN_CHECK_LAST_NAME
AddStrings $AFN_tmp $AFN_firstName
If $AFN_middleName = "" Then AFN_CHECK_LAST_NAME
AddStrings $AFN_tmp " " $AFN_middleName

:AFN_CHECK_LAST_NAME
GetLine $AFN_lastName 7 $AFN_fieldList
Trim $AFN_lastName
If $AFN_lastName = "" Then AFN_CHECK_FOR_NO_NAMES
If $AFN_firstName = "" Then AFN_ADD_LAST_NAME
AddStrings $AFN_tmp " "
Goto AFN_ADD_LAST_NAME

:AFN_CHECK_FOR_NO_NAMES
If $AFN_firstName = "" Then AFN_CHECK_NICKNAME
Goto AFN_CHECK_SUFFIX

:AFN_ADD_LAST_NAME
AddStrings $AFN_tmp $AFN_lastName

:AFN_CHECK_SUFFIX
GetLine $AFN_suffix 53 $AFN_fieldList
Trim $AFN_suffix
If $AFN_suffix = "" Then AFN_FINISHED_NAME
AddStrings $AFN_tmp ", " $AFN_suffix

:AFN_FINISHED_NAME
AddStrings $AFN_tmp $AFN_company "\" " $AFN_address
Set $AFN_address $AFN_tmp
Return

{3) NICKNAME (Company)
:AFN_CHECK_NICKNAME
GetLine $AFN_nickname 0 $AFN_fieldList
Trim $AFN_nickname
If $AFN_nickname = "" Then AFN_CHECK_COMPANY
Set $AFN_tmp ""
AddStrings $AFN_tmp "\"" $AFN_nickname $AFN_company "\" " $AFN_address
Set $AFN_address $AFN_tmp
Return

{4) COMPANY
:AFN_CHECK_COMPANY
If $AFN_company = "" Then Return
Set $AFN_tmp ""
AddStrings $AFN_tmp "\"" $AFN_companyOriginal "\" " $AFN_address
Set $AFN_address $AFN_tmp
Return
Last edited by Pete on Tue Nov 16, 2004 5:04 pm, edited 3 times in total.
Pete
 

Postby Sandy » Tue Nov 16, 2004 1:39 pm

UNBELIEVABLE use of subroutines (and what subroutines)!!

I can't even imagine debugging this monster.

VERY
impressive.

[later edit: I can imagine all this is a regular language, but with PocoScript's limited subroutine support, lack of proper loop commands, and not even a true IF....Else....Then]................WOW
Sandy
 

Postby Pete » Tue Nov 16, 2004 5:12 pm

Thanks, Sandy. Yeah, the code in the last subroutine (ADD_FULL_NAME) is true "spaghetti code". :)
It would be so much easier if we had the constructs that you mentioned and we could use subroutines with local variables (rather than prefixing each variable with extra letters) and if we could use multiple conditions in a single IF statement, etc., etc.

To anyone that reads this topic, I've just changed the script in the following ways:

(1) Always put Company Name (if it exists) at end of Full Name.

(2) Made Nickname more important than Company Name.
Pete
 


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 0 guests

cron