In Mail app, how can I go (jump) to the folder (mailbox) of a selected message in a search result view or in a Smart Mailbox? In Mail app I work with many smart mailboxes and I and usually need to jump to the mailbox where the message is really filed.

It's the same with search results - I usually need to locate the folder (mailbox) where a message I selected in the result view is filed.

For previous versions of Apple Mail (at least up to Mavericks) I could do the same as I did in many other applications to locate the folder of the opened document in a window.

In the case of Mail.app:


Open the message (double-click)
Right-click the windows title bar where the subject of the message
appear
You will see the path of that message
Select the desired folder


When I moved from Maverick to Sierra I sadly discovered that the previous approach did not work any more.

How can I fix this or achieve the same functionality?
Solution using AppleScript

The solution I found was to create an Automator service and associate it to a shortcut.


Open Automator
New Document
Select "Service" for the type of document
At the top of the window, set the following options:
Service receives selected >> no input
in >> Mail.app
In the Actions library (left pane) find the action "Run AppleScript"
Drag and drop it in the workflow area
Copy the code at the end of this answer and paste it into the action "Run AppleScript"
Save your service (e.g. "Jump to Folder")


Test the service


No need to close automator or relaunch Mail.
Do a search and select a message (preferably a message filed in some custom folder).
Go to Mail >> Services. You should see your new service
Apply the service.


Your selected and active mailbox should be the mailbox of the previously selected message.

Optional

Assign a shortcut (e.g. CONTROL-COMMAND-J) to your service:


System Preferences >> Keyboard >> Shortcuts >> Services.
At the end of the right pane under General you should find your service.
Assign a shortcut to it.


The Code

set theDialogTitle to "Jump to Folder Script"

tell application "Mail"

    -- Get the selected messages and the count of them
    set theMessageList to selected messages of message viewer 1
    set theCount to length of theMessageList

    -- Error if no messages
    if theCount is 0 then
        display dialog ¬
            "No message selected." with title theDialogTitle buttons {"OK"} with icon caution
        return
    end if

    -- Error if more than one message
    if theCount is greater than 1 then
        display dialog ¬
            "Must select only one message." with title theDialogTitle buttons {"OK"} with icon caution
        return
    end if

    -- Get the message
    set theMessage to item 1 of theMessageList

    -- Get the mailbox object
    set theMailbox to mailbox of theMessage

    -- Select the mailbox
    set selected mailboxes of message viewer 1 to theMailbox

end tell