Save attachments from an email located on a server volume


I have a few emails in a folder on my server. I’m looking for a script, that saves all the attachments form that mails to a defined folder.

I searched an find scripts that work fine, if the mails are in a mailbox of the

Here is my script so far:

set KundenDatenOrdner to PFAD:zum:SERVER
set selectedMessages to files of (KundenDatenOrdner as alias)
set attachmentsFolder to KundenDatenOrdner as text
tell application "Mail"
		repeat with theMessage in selectedMessages
			open theMessage
			-- Get the date the message was sent
			set {year:y, month:m, day:d, hours:h, minutes:min} to theMessage's date sent
			set timeStamp to ("" & y & "-" & my pad(m as integer) & "-" & my pad(d) & "-" & my pad(h) & "-" & my pad(min))
			if theMessage's mail attachments exists then
				-- Save the attachment
				repeat with theAttachment in theMessage's mail attachments
					set originalName to name of theAttachment
					set savePath to attachmentsFolder & ":" & originalName
						save theAttachment in savePath
					end try
				end repeat
			end if
		end repeat
	end tell

Thanks for your help