Mailsmith
Other Programs
Scripts
Mailsmith.scpt
Archive to sub-mailbox
Check Spelling
Find reply
Change font size
Submit Script to JEM
Fix common spelling errors
Setting SMTP server
URL from Safari
Address from AB
linkMunge
Export to Address Book
Saving attachments
Digest Script
File with same
POP window position
Position of new windows
iCal and Mailsmith
Edit From Line
Modified Thread Script
Reply to Selection
Temporary Text Window
Compact gain
Tracking backups
Edit subject
Googler
Auto-rewrap
MMA
SMTP server
Open, fetch, and close
URL Manager
BrainForest
Thread by Author
Thread by subject
Export Email
Get Selection
Read Addresses
Export Email
Organize Email
Account setup
Mailsmith 2 BBEdit
BBEdit 2 Mailsmith
Search II
Check One
Delete Enclosure
Open, fetch, close
Set Answered
Set Redirected
Empty Trash
List found
Print Several
Del. old. msg.
Delete Enclosures
Accounts
Address Book
Editing
Filters
General
Import/Export
Links
Mailboxes
Memory
Scripting
Speed
send/receive
Tips/Tricks


Thread by subject

Author Jan Erik Moström
Last modified 2001-03-12
What is this?

This script takes the message(s) that you have selected and collects all messages in the same mailbox that has the same subject line. Before collecting them it strips the subject of any "Re:", "Sv:", "Fwd:" etc. It also strips any trailing spaces.

Note that you can add more prefixes by adding more strings to the property 'prefixList' (first line)

See also the script "Thread by author"


property prefixList : {"Re:", "Sv:", "Atw:", "Fwd:"}

on run
  tell application "Mailsmith 1.1"
    set xs to selection
    if class of xs ≠ list then
      set xs to xs as list
    end if
    repeat with currentItem from 1 to the number of items of xs
      set m to item currentItem of xs
      -- Check to make sure that the selection is something
      -- the script understands what to do with
      if class of m = string then
        set m to message of window 1
      else if class of m ≠ message then
        display dialog ¬
          "Oppps, you have to select a message for this script to work" buttons {"OK"} default button "OK"
        return
      end if
      set c to container of m
      set s to subject of m
      -- Trim the subject line of "Re:", "Sv:" and similar prefixes
      set s to my subjectTrim(s)
      make new mail list window with data every message of c whose subject contains s with properties {name:"Thread: " & s}
    end repeat
  end tell
end run

on subjectTrim(str)
  global prefixLength
  repeat while length of str > 0 and hasPrefix(str)
    set str to (text (prefixLength + 1) thru (length of str) of str) as text
    -- Now remove spaces
    repeat while str starts with " " and length of str > 0
      set str to (text 2 thru (length of str) of str) as text
    end repeat
  end repeat
  -- OK beginning fixed, I wonder if there should be some
  -- code here to fix the ending ... OK, but it's probably not necessary
  repeat while str ends with " " and length of str > 0
    set str to (text 1 thru -2 of str) as text
  end repeat
  return str
end subjectTrim

on hasPrefix(str)
  global prefixLength
  set lastItem to number of items of prefixList
  repeat with i from 1 to lastItem
    if str starts with item i of prefixList then
      set prefixLength to length of item i of prefixList
      return true
    end if
  end repeat
  return false
end hasPrefix