Operations on selected messages in Eudora

I am trying to improve a script I wrote for reporting spam to SpamCop in Eudora http://theapotek.com/teknotes/archives/000037.html. I would like it to be able to perform its routines on several selected e-mail at once, instead of just one at a time. The syntax I wish would work, looks like this:

tell application “Eudora”
set messageCount to (count every message of selection)
repeat with n from 1 to (messageCount - 1)
–Do the work here
end repeat
end tell

This does not work (can’t get every …). Does anyone have a script where you’ve succeeded in creating an iterable list of selected messages in Eudora? I’m using Eudora 6 and Mac OS 10.2.

Your help is appreciated.

All credit for this technique goes to John Delacour (a Eudora script god). I’ve modified it only slightly to try to make it close to what you have asked for.

set messIDs to {}

tell application "Eudora"
	activate -- for testing only 
	set vBox to the name of the front window
	try
		set x to name of mailbox vBox
	on error e
		tell me to return (display dialog e & " 
(A mailbox summary must be frontmost) 
" with icon 0 buttons {"OK"} default button 1 giving up after 1)
	end try
	repeat
		try
			copy id of (move message "" to end of mailbox vBox) to end of messIDs
		on error
			exit repeat
		end try
	end repeat
	
	repeat with id_ in messIDs
		-- do something to message id_
	end repeat
end tell

– Rob

An Applescript named “Eudora to SpamCop 1.0.1” has been uploaded to our ScriptBuilders section. It might have some code in it to help you with your script.

I think this is the scripter who submitted that script. :wink:

– Rob

Thanks to Rob and John Delacour I’ve gotten to the point where I can iterate through selected messages. The only difficulty I’m having is that both sample solutions leave the messages in a state of being deselected after having been processed, which means the user would have to re-select them in order to do any further work with them (such as declaring them Junk*, or moving them to the trash). I guess that’s the next mountain to climb.

Here’s the code John Delacour sent me:

tell app "Eudora"
  set ls to {}
  set _senders to {}
  set w to the name of the front window
  try
    file of mailbox w
  on error
    tell me to display dialog "
A mailbox summary must be frontmost" with icon 0
    return
  end
  repeat
    try
      set end of ls to move message "" to end of mailbox w
    on error
      exit
    end
  end
  repeat with m in ls
    set end of _senders to sender of m
  end
  _senders
end

  • At some point, I’d like to get my script to be able to do this automatically, but that’s for another day.

Yup. That would be me.

I’ve been advised by JD that my script is flawed because “The id of a message is unique and will not change when you move it, but it is not sufficient as a reference”. Here’s the sample code that he has provided.

set _messages to {} -- place holder for selected messages
set _misclist to {} -- place holder for data from messages
tell application "Eudora"
	set w to the name of the front window
	try -- make sure a mailbox is frontmost...
		set _mbx to name of mailbox w
	on error e
		tell me to display dialog e & "
(A mailbox summary must be frontmost)
" with icon 0 buttons {"OK"} default button 1 giving up after 1
		return -- ... and give up if not.
	end try
	repeat
		try
			set end of _messages to move message "" to end of mailbox _mbx
			-- move it to just where it already is
		on error -- error occurs when last message is deselected
			exit repeat
		end try
	end repeat
	
	repeat with _message in _messages
		set _message to contents of _message -- not always needed
		set end of _misclist to subject of _message
	end repeat
	_misclist
end tell

Sorry 'bout that! I would have sworn that I had referred to messages by ID in the past but I guess not! :oops:

– Rob (who is now going to inspect all of his Eudora scripts) :wink:

In this example, the variable ‘ls’ is a list of references to the messages that were selected. So, use the repeat loop at the end of the script to work through the list of messages and have your way with them.

 repeat with m in ls
    -- do something to m -- m is a message that was selected
  end

– Rob

Okay, so I have the script running through using references, rather than ids. However, there are two ways the user can report spam. 1: By selecting a file or several files in a mailbox. When the user does that, file references are inserted into the _messages list. So far, so good.

However, I also want the user to be able to process a message that has been opened. But of course, when I pass

set end of _messages message ""

and message “” refers to the open window, I don’t get a file reference, I get the message itself.

This means that I can’t treat the _messages list the same in both instances. Obviously, I could create two separate subroutines for each case, but that’s pretty messy. The best answer would be if I could find a way to make a file reference out of an open window. I tried hand-making one like this:

set end of _messages to message "" --"message id " & thisMessageId & " of mailbox "" & thisMessageMailboxName & "" of application "Eudora""

.

That did not work. Any hints? :?:

I believe that this will create the reference that you are looking for.

set end of _messages to a reference to message id (id of message "") of (get mailbox of message "")

– Rob

Hey! Now it’s me that losing my marbles! javascript:emoticon(‘:?’)

I could have sworn that property of a message was not there before, but I see it’s there as far back as 3.1.3 at least, so YES --that’s the way to do it or

tell application "Eudora"
	set {b, i} to {mailbox, id} of message ""
	set m to a reference to message id i of b
end tell

:smiley: That did it! Perfect. That allowed me to clean up most of the cruft in my script. Interesting to me that there was no mention of ‘reference’ in the Eudora dictionary. I take it references are standard parts of AppleScript and can be made for most objects. I’ll have to play around with ‘reference’ to see what it can do. In any even, my script, thanks to help here and other places, is much improved, and now at v 1.1 with more features, and much cleaner implementation. http://scriptbuilders.net/category.php?search=Eudora+to+SpamCop. Someday, it will be nice to revisit the question of being able to collect a list of selected messages without leaving them deselected, but that’s for another day.