------------------------------------------------------------------------------------------------
# Requires the Satimage.osax for 'find text', 'join', 'sortlist', 'splittext'
------------------------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------------------------
on cng(findText, changeText, srcData)
return change findText into changeText in srcData with regexp without case sensitive
end cng
------------------------------------------------------------------------------------------------
on fnd(findStr, srcData, caseSensitive, allOccurrences, stringResult)
try
set findResult to find text findStr in srcData case sensitive caseSensitive all occurrences allOccurrences ¬
string result stringResult with regexp
return findResult
on error
return false
end try
end fnd
------------------------------------------------------------------------------------------------
on fndUsing(fndStr, returnStr, srcData, caseSensitive, regExFlag, wholeWord, allOccurrences, stringResult)
try
set findResult to find text fndStr in srcData case sensitive caseSensitive regexp regExFlag ¬
whole word wholeWord using returnStr all occurrences allOccurrences string result stringResult
return findResult
on error
return false
end try
end fndUsing
------------------------------------------------------------------------------------------------
--» MAIN
------------------------------------------------------------------------------------------------
try
set mbx to {}
tell application "Mail"
try
mailboxes / 0
on error e
end try
set e to cng("(?:, )?«class mbxp» "
, "
\\r"
, e) of me set e to cng("
\\s*of application.+"
, ""
, e) of me set e to cng("\"", "", e) of me
set e to cng("^(Deleted Messages|Notes|Outbox)$\\r{,1}", "", e) of me
set mailboxNames to join fnd("[^/]+$", e, false, true, true) of me using return
set mailboxNames to splittext mailboxNames using return
set mailboxNames to sortlist mailboxNames comparison 2
set selectedMailboxName to choose from list mailboxNames with empty selection allowed
if selectedMailboxName is not false and selectedMailboxName is not {} then
set selectedMailboxName to item 1 of selectedMailboxName
set selectedMailboxName to cng("([?.*()\\[\\]{}])", "\\\\\\1", selectedMailboxName) of me
set mailBoxRef to fnd("^.*" & selectedMailboxName & "$", e, false, false, true) of me
set mailBoxRef to mailbox mailBoxRef
tell (some message viewer whose index is 1)
set selected mailboxes to {mailBoxRef}
end tell
end if
end tell
on error eMsg number eNum
set {c, s} to {return, "------------------------------------------"}
set e to s & c & "Error: " & eMsg & c & s & c & "Error Number: " & eNum & c & s
beep
display dialog e
end try
------------------------------------------------------------------------------------------------