Importing an already imported email could cause such messages (or trying to move an email into a database containing this email alread). How do you exactly import and move the items?
1. The emails are added to the inbox via a rule in Apple Mail which runs this AppleScript.
property pDatabasePath : ""
-- This string is used when the message subject is empty
property pNoSubjectString : "(no subject)"
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
-- Location of destination groups.
set pMessageLocation to "/" & (name of theRule)
-- set pAttachmentLocation to pMessageLocation & "/Attachments"
tell application id "DNtp"
if pDatabasePath is "" then
set destination_database to inbox
else
set destination_database to open database pDatabasePath -- Ensure that the database is open
end if
set message_group to create location pMessageLocation in destination_database
-- set attachment_group to create location pAttachmentLocation in destination_database
end tell
tell application "Mail"
set theFolder to (POSIX path of (path to temporary items))
repeat with theMessage in theMessages
try
tell theMessage
set {theDateReceived, theDateSent, theSender, theSubject, theSource, theReadFlag} to {the date received, the date sent, the sender, subject, the source, the read status}
end tell
if theSubject is equal to "" then set theSubject to pNoSubjectString
tell application id "DNtp" to set message_group to create location theSubject in destination_database
tell application id "DNtp" to create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string), unread:(not theReadFlag)} in message_group
repeat with theAttachment in mail attachments of theMessage
set theFile to theFolder & (name of theAttachment)
tell theAttachment to save in theFile
tell application id "DNtp"
set theAttachmentRecord to import theFile to message_group
set unread of theAttachmentRecord to (not theReadFlag)
set URL of theAttachmentRecord to theSender
end tell
end repeat
end try
end repeat
end tell
end perform mail action with messages
end using terms from
2. A set of smart-rules in the inbox then automatically files the emails into the relevant database, based on the presence of @[string] in the subject. For example, if the email has “@tax” in the subject, then it’ll be filed into the Tax database.
This action causes the error message as an email with the same message ID exists already in the destination database. This could e.g. happen if the rule in Apple Mail is performed several times on the same emails (but Apple Mail’s rule handling is in my experience although not always reliable).