The following steps will allow you to create a new folder for spam messages, and have Thunderbird move any messages containing X-Spam-Flag: YES into that folder..
Launch Thunderbird. Click File -> New -> Folder.
Name the folder as you wish and click OK.
Click Tools -> Message Filters.
Click ‘New’ to add a new filter.
Give the filter a descriptive name and click ‘Match any of the following’. Select ‘Customize’ from the top left drop-down menu.
Enter ‘X-Spam-Flag’ (without the quotes), click Add, and then click OK.
Type ‘YES’ (all caps, no spaces) in the top right box. It should read: X-Spam-Flag / contains / YES. Under ‘Perform these actions’, select ‘Move Message to’ and then select the new folder you created. Click OK.
Ensure the new rule is Enabled. You can also optionally run the filter on your mail folders right now.