[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 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 - Display Nickname and raw email address in Message Index Pane

Display Nickname and raw email address in Message Index Pane

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Display Nickname and raw email address in Message Index Pane

Postby frazmi » Tue Aug 24, 2004 11:48 pm

Scenario 1: I have several contacte with multiple email accounts, and they use different "names" for each account. I want to "clump" all their messages together by sorting on something. No way in standard Poco, AFAIK.

Scenario 2: I have a big mailing list, and I want to strip out the duplicates. Very difficult, since I might have several different contact records with the same email address.

The following script addresses these and other scenarios. Basically, it adds 2 X-headers to the message, and then uses the custom column display capability to show nickname and email address. It requires multiple address book entries, one per email address (but with the same nickname), in order to get the "clumping" I need in scenario 1.

It can be run manually on an existing mailbox, or set up as an incoming filter. It also works on an OnAdd event

If anybody wants to add error checking to this, please do so.

Code: Select all
{Script to add headers to messages containing nicknames
{and raw email address. Used in conjunction with the custom
{column display, they allow the splitting of the nickname
{and the email address into 2 separate columns. In addition,
{'my' name for a contact is displayed in preference to
{the name selected by the contact in the incoming email.
{This can be set up as an incoming filter, or run manually.
{Not tested: it should also work with an event.
{Placed into the public domain by Frazmi on 25 August 2004
{Please test thoroughly and over and over before you use this
{on a production basis. The standard 'FrazWarranty' applies:
{It works on my system. It might fail on yours.
{
{Revision 1 -- Fixed bug pointed out by Hoygt. If run on message
{in Sent folder, and there are multiple addressees, the original
{script added "header" lines with no header prefix. This revision
{concatenates all the "to" addresses into a single line.
{
{Revision 2 -- Changed the last code block to use the variables
{for EmailHeader and NicknameHeader -- they were hard coded.
{Also added the line "ExtractEmail $Email" in the section :OUTGOING
{which had been inadvertently deleted in the previous bug fix.

Set $EmailHeader "X-Email"
Set $NicknameHeader "X-Nickname"

IF $CurrentMailbox = "In" THEN INCOMING
IF $CurrentMailbox = "Sent" THEN OUTGOING

ReadHeader $Status "X-Poco-Status" %message
IF $Status = "R" THEN INCOMING
IF $Status = "RW" THEN INCOMING
IF $Status = "RF" THEN INCOMING
IF $Status = "U" THEN INCOMING
IF $Status = "RS" THEN OUTGOING
EXIT

:OUTGOING
Set $Email ""
ReadTo $To %message
:Outgoing2
      LineCount #To $To
      IF #To = 0 THEN EndOutgoing  {ELSE}
            GetLine $temp 0 $To
            DeleteLine $To 0
            AddStrings $Email $temp
            IF #To = 1 THEN EndOutgoing {ELSE}
                  AddStrings $Email ", "
                  GOTO Outgoing2
:EndOutgoing
GOTO TestEmail

:INCOMING
ReadHeader $Email "From" %message
ExtractEmail $Email

{Delete all previous special headers
:TestEmail
ReadAllHeaders $Headers %message
LocateLine #Header $EmailHeader $Headers
IF #Header = -1 THEN TestNickname
      DeleteHeader $EmailHeader %message
      GOTO TestEmail

:TestNickname
ReadAllHeaders $Headers %message
LocateLine #Header $NicknameHeader $Headers
IF #Header = -1 THEN WriteHeaders
      DeleteHeader $NicknameHeader %message
      GOTO TestNickname

:WriteHeaders
{ExtractEmail $Email
GetAddressField $Nicky $Email "nick"
AddHeader %message $NicknameHeader $Nicky
AddHeader %message $EmailHeader $Email
SaveMessage %message $CurrentMailbox
DeleteMessage %message

[Edit 1] Fixed (I hope) bug pointed out by Hogyt.
[Edit 2] Fixed two more bugs. See revision text in script.
Last edited by frazmi on Wed Aug 25, 2004 1:16 am, edited 2 times in total.
frazmi
Poco Enthusiast
 
Posts: 248
Joined: Tue Jul 27, 2004 1:27 am
Location: South Korea

Postby Hogyt » Wed Aug 25, 2004 12:20 am

Thats nice Frazmi! :D I've completely run out of custom columns now :roll:

Theres one tiny problem with the script but its nothing major. If the to header has multiple recipients and the script is run on that message in the sent mailbox then the new x-poco-email header has a small problem. I think maybe it needs commas at the end of each line since if i re-run the script on that message the first line of the x-poco-email header is removed but it leaves the rest of the header as it is, and then duplicates it again, leaving a bit of a mess. So after two runs i get the headers:

b@b.com
c@c.com
X-Poco-Nickname:
X-Poco-Email: a@a.com
b@b.com
c@c.com

Maybe the easiest solution is to take the first line of the to header and forget the rest when creating x-poco-email?
Mat
Hogyt
Poco Enthusiast
 
Posts: 241
Joined: Thu Jul 29, 2004 11:22 am
Location: England

Postby frazmi » Wed Aug 25, 2004 12:53 am

Thanks for noticing the bug. I've edited the script (see above) so that multiple TO addresses are concatenated into the single header, separated by commas.
frazmi
Poco Enthusiast
 
Posts: 248
Joined: Tue Jul 27, 2004 1:27 am
Location: South Korea

Postby frazmi » Wed Aug 25, 2004 1:19 am

Two other bugs needed squashing. When I edited the first version of the script, somehow a line got dropped. And the last code block didn't use the variables that hold the header names.

I've changed the header name to X-Nickname and X-Email in order to fix a display problem when the Poco display font is large. But you can set them to anything you want.

One caution, once you've set the header names, re-running the script will not catch and delete the headers if you change the header names. You would have to modify the script in such an event. In other words, test it a lot before you use it on "real" messages.
frazmi
Poco Enthusiast
 
Posts: 248
Joined: Tue Jul 27, 2004 1:27 am
Location: South Korea


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 2 guests

cron