阅读349 返回首页    go iPhone_iPad_Mac_apple


Script sometimes move wrong mail content to DT ...

OSX - El Capitan 10.11.6 & macOS Sierra 10.12.6:

 

I wrote a small Applescript which is invoked thru an special subject in incoming mails (mail rules).

This script should store the mail(subject, content etc.) into a subfolder of an special DT database and move it then into a subfolder in mail.

 

Usually the script is running fine an worked as expected.

But sometimes it stores NOT the original mail but the next incoming mail (with different mail-subject,-content etc.)into DT and sometimes nothing is stored in DT.

Sometimes the correct mail is then moved to a subfolder, but sometimes nothing happens (mail remain in the input folder).

 

I've tried several times to debug the problem, but actually I can not postpone the situtation.

 

Here is the code:

property pNoSubjectString : "(no subject)"
property nameDatabase : "~/Documents/DMS/MyDatabase.dtBase2"
property nameGroup : "/Office/Subfolder1/„
property nameDestinationMailbox : „Subfolder2“
property nameDestinationMailboxMail : „Folder/SubFolder“

using terms from application "Mail"
   on perform mail action with messages theSelectedMessages for rule theRule
      tell application "Mail"
         repeat with theMessage in theSelectedMessages
            set theAccount to name of account of mailbox of theMessage
            tell theMessage
               set {theDateReceived, theDateSent, theSender, theSubject, theSource, theReadFlag} to {the date received, the date sent, the sender, the subject, the source, the read status}
            end tell
            if theSubject is equal to "" then
               set theSubject to pNoSubjectString
            end if
            tell application id "DNtp"
               try
                  set theDatabase to open database nameDatabase -- Ensure that the database is open
                  set theGroup to create location nameGroup & nameDestinationMailbox in theDatabase
                  set existingEntries to search theSubject & ".eml" in theGroup
                  set existingRecordNumber to count of existingEntries
                  if ((count of existingEntries) = 0) then
                     create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string), unread:(not theReadFlag)} in theGroup
                  end if
               on error error_message number error_number
                  if error_number is not -128 then display alert "Mail" message error_message as warning
               end try
            end tell
            -- now move the message into another mail subfolder
            move theMessage to mailbox nameDestinationMailboxMail of account theAccount -- a folder contained by another folder
         end repeat
      end tell
   end perform mail action with messages
end using terms from

I have already asked this question in the DT forum. But there you couldn´t find an error in the coding and recommended to me to turn to this forum here.

 

Any help is appreciated.



最后更新:2017-08-24 23:35:30

  上一篇:go 10 second delay after pressing power button
  下一篇:go How to archive mail in Sierra