Mailablage in DTPO

Hallo,

ich möchte gerne meine Mails komplett in DTPO speichern und wenn möglich in der gleichen Ordnerstruktur wie in Apple Mail abbilden. Wenn ich nun die Mails über Impotieren/E-Mail/ Postfach archivieren übertrage, bekomme ich die gleiche Struktur wie die Ablage bei Apple Mail, jedoch hab ich dann das Problem, daß die Anhänge ( meist PDF ) nicht durchsuchbar sind.
Speichere ich die Mails über ein Script in Apple Mail nach DTPO, bekomm ich ich durchsuchbare Mails, jedoch eine andere Ordnerstruktur.

Wie schaffe ich es, die gewünschte Struktur mit durchsuchbaren Anhängen ohne komplizierte Ausführungen herzustellen?

Welches Script verwenden Sie denn konkret?

Hallo,

daß Script in Apple Mail, als zusätzliches Modul installiert und mit voller Durchsuchbarkeit ist "Mail Rule-File Messages & Attachments ". Hier muß ich aber extra jeden einzeln Ordner zu Devonthink weiterleiten.
Die andere Möglichkeit ist das importieren direkt von Devonthink aus. Reiter Ablage/ Importieren /Email. Hier bekomme ich die Ordnerstruktur ,jedoch lassen sich dann die Anhänge( PDF) nicht über die Suchfunktion durchsuchen.

Was Sinn macht, ist die Ordnerstruktur beizubehalten und gleichzeitig durchsuchbare Anhänge zu generieren. Weil sonst muß ich ja wieder alles händisch sortieren. Ich möchte jedoch solche Dinge automatisieren, sonst kann ich eigentlich weiter meine Papierordner durchblättern.
Wäre klasse, wenn es da Script etc. gäbe, die mich darin entlasten.

Die Skripte lassen sich natürlich relativ leicht anpassen:


-- Import selected Mail mailboxes & attachments to DEVONthink Pro.
-- Created by Christian Grunenberg on Wed Aug 03 2005.
-- Copyright (c) 2005-2018. All rights reserved.

-- this string is used when the message subject is empty
property pNoSubjectString : "(no subject)"

-- The location for the mails to import as a POSIX path ("/" is the top level of the database)
property pLocation : "/Apple Mail"

on importMessage(theMessage, theFolder, theGroup)
	tell application "Mail"
		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
			set theAttachmentCount to count of mail attachments of theMessage
			tell application id "DNtp"
				if theAttachmentCount is greater than 0 then set theGroup to create record with {name:theSubject, type:group} in theGroup
				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 tell
			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 theGroup
					set unread of theAttachmentRecord to (not theReadFlag)
					set URL of theAttachmentRecord to theSender
				end tell
			end repeat
		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
end importMessage

on exportMailboxToDEVONthinkPro(theMailbox, theFolder)
	local theMailbox, theMailboxes, theMailboxName, theCount, theGroup, theMessage, theSubject, theLocation, theContainer, theContainerName
	tell application "Mail"
		--	try
		set theMailboxName to name of theMailbox
		set theCount to (count of messages in theMailbox)
		if theCount > 0 then
			set theLocation to ""
			
			try
				set theContainer to theMailbox
				repeat
					set theContainerName to name of theContainer
					set theLocation to my replaceCharacter(theContainerName, "/", "-") & "/" & theLocation
					set theContainer to container of theContainer
				end repeat
			end try
			set theLocation to pLocation & "/" & theLocation
			
			tell application id "DNtp"
				set theGroup to create location theLocation
			end tell
			repeat with theMessage in every message of theMailbox
				set theSubject to the subject of theMessage
				tell application id "DNtp"
					step progress indicator theSubject
					if cancelled progress then return false
				end tell
				my importMessage(theMessage, theFolder, theGroup)
			end repeat
		end if
		set theMailboxes to the mailboxes of theMailbox
		repeat with theMailbox in theMailboxes
			if not my exportMailboxToDEVONthinkPro(theMailbox, theFolder) then return false
		end repeat
		-- end try
	end tell
	return true
end exportMailboxToDEVONthinkPro

on replaceCharacter(theString, theOriginalChar, theNewChar)
	set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, theOriginalChar}
	set theStringParts to text items of theString
	if (count of theStringParts) is greater than 1 then
		set theString to text item 1 of theStringParts as string
		repeat with eachPart in items 2 thru -1 of theStringParts
			set theString to theString & theNewChar & eachPart as string
		end repeat
	end if
	set AppleScript's text item delimiters to od
	return theString
end replaceCharacter

on countMessages(theMailboxes)
	local theCount, theMailbox
	set theCount to 0
	tell application "Mail"
		repeat with theMailbox in theMailboxes
			set theCount to theCount + (count of messages in theMailbox)
			set theCount to theCount + (my countMessages(mailboxes of theMailbox))
		end repeat
	end tell
	return theCount
end countMessages

tell application "Mail"
	activate
	set activated to false
	try
		set selectedMailboxes to selected mailboxes of front message viewer
		if (the count of selectedMailboxes) > 0 then
			set theFolder to (POSIX path of (path to temporary items))
			tell application id "DNtp"
				activate
				if not (exists current database) then error "No database is open."
				set activated to true
				show progress indicator "Adding mailboxes" steps (my countMessages(selectedMailboxes)) with cancel button
			end tell
			repeat with theMailbox in selectedMailboxes
				if not my exportMailboxToDEVONthinkPro(theMailbox, theFolder) then exit repeat
			end repeat
			tell application id "DNtp"
				hide progress indicator
				activate
			end tell
		else
			error "One or more mailboxes must be selected."
		end if
	on error error_message number error_number
		if activated then tell application id "DNtp" to hide progress indicator
		if error_number is not -128 then display alert "Mail" message error_message as warning
	end try
end tell

Hallo,

Danke für die schnelle Hilfe mit dem Skript.
Leider funktioniert es suboptimal. Es sind zwar alle Mails durchsuchbar, nur legt er mir die Mails fast immer vierfach ab.
D.h. aus 2000 Mails, wurden in DTPO knapp 8000 Mails :question:
Das andere Problem, wenn ich dann dieses Script als Regel in Apple Mail anlege, werden immer wieder neu alle Mails kopiert. Ich kann also nicht diese Regel anwenden, quasi einmal alles herunterladen, um dann die täglich neusten anfallenden Mails somit automatisch in die vorhandene Struktur einfliesen zu lassen.

Könnte man die Duplikate minimieren und das Script so umschreiben, daß zum einem die Apple Mail Ordnerstruktur beibehalten wird, Mails und Anhänge (PDF) durchsuchbar bleiben und die neusten Mails automatisch (als Regel) jeden Tag hinzufügen werden?
Das wäre echt super, wenn dies möglich wäre.

Das Skript ist für das entsprechende Menü Extra gedacht und importiert die aktuell ausgewählten Mailboxen, bei Ausführung als Regel werden somit entweder die falschen Emails/Mailboxen importiert oder Duplikate erzeugt.

Hallo,

Und worin besteht dann der Sinn von diesem Script?
Dann leg ich mir Gulasch aufs Brot und kau solange bis ich ein Mettbrötchen hab :smiley: und so schließt sich meine Frage an, wie man dieses Problem etwas sinnvoller gestalten kann?
Falls sich das per script nicht lösen läßt, welche Alternative könnte man einbauen oder gibt es eine Möglichkeit, bei Apple Mail eine Regel zu verwenden, die Mails in einen Ordner auf den Mac kopiert (natürlich automatisch) um dann mit Hazel einen Weg zu finden?

Es gibt Skripte für Regeln und für das Menü Extra, aus der ursprünglichen Anfrage ging nicht hervor, was genau verwendet wird :open_mouth:

Keine Rippchen heute? :smiley:

Natürlich lassen sich auch die Skripte für Apple Mail-Regeln anpassen:


-- POSIX path of destination database. Global inbox is used if not specified.
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
		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
		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}
						
						-- Location of message
						set theMessageLocation to "/"
						try
							set theMailbox to mailbox of theMessage
							repeat while theMailbox is not missing value
								set theName to name of theMailbox
								set theMessageLocation to "/" & (theName as string) & theMessageLocation
								set theMailbox to container of theMailbox
							end repeat
						end try
						set theMessageLocation to "/Apple Mail" & theMessageLocation
					end tell
					
					set numAttachments to count of mail attachments of theMessage
					if theSubject is equal to "" then set theSubject to pNoSubjectString
					
					tell application id "DNtp"
						set message_group to create location theMessageLocation in destination_database
						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
						if numAttachments > 0 then set attachment_group to create location theMessageLocation & "/Attachments" in destination_database
					end tell
					
					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 attachment_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

Hallo Hr. Grunenberg,

ich hoffe Deine Geduld ist noch nicht erschöpft.
Mit dem letzten erstellten Script geht das Ganze schon in die richtige Richtung.
Der einzige Mißstand ist, daß alle Mails gemäß meiner Ordnerstruktur wie in Apple MAIL abgelegt werden können und PDF durchsuchbar sind, jedoch dies ausschließlich in der Globalen Inbox geschieht.
Mein laienhafter Versuch, daß Script etwas anzupassen, scheitert kläglich an meiner fehlenden Kenntnis darüber, wo der Hebel angesetzt werden könnte.
Wie schaffe ich es, daß das in den Regel von Apple Mail angewandte Script(siehe Dein Post vom 27.02), mir die Mails nicht in die Globale Inbox sendet, sondern in eine von mir erstellte Datenbank?
In dieser Datenbank sollen automatisch die gesendeten und empfangenen Mails gespeichert werden, damit ich eine Sicherungskopie zu meinem NAS durchführen kann.

Leider habe ich auch keine Möglichkeit gefunden, automatisch über “Intelligente Ordner” vom Globalen Eingang zu einer von mir angelegten Datenbank mein Vorhaben zu realisieren, bzw. die Mails zu verschieben.

Kartoffelbrei und Sauerkraut dazu… :mrgreen:

Was mir gerade noch auffällt: Wenn ich DTPO beende und dann eine Mail in einen gewüschten Ordner versende, öffnet sich DTPO automatisch und legt nun diese Mail in die zuletzt geöffnete Datenbank ab oder in die Intelligenten Gruppen , je nachdem wo ich vor dem schliessen zuletzt aufgehalten hab. Kann man das in diesem Script verhindern, mit der Zuweisung nur einer Datenbank?

und mit Kümmel übern Kraut etwas abrunden… :wink:

Es sollte reichen, pPropertyPath entsprechend zu modifizieren, also z.B.


property pDatabasePath : "/pfad/zu/meiner/datenbank/name.dtBase2"

Hallo Hr. Grunenberg,

klasse, daß mit der Pfad Eingabe ist erfolgreich.

Ich habs es mit etwas Zauberei (sinnfreier Drückerei) geschafft, daß nun zum einen der Altbestand 1 zu 1 in DTPO wie in Mail abgebildet ist.
Alle gesendeten und empfangenen Mails werden automatisch abgespeichert.

Aber: Die empfangenen Mails werden immer doppelt im jeweiligen Ordner gespeichert :frowning:
Bei den gesendeten Mails jeweils nur eine.
Liegt das an dem Sript für die Regel in Mail oder gibt es die Möglichtkeit, den intelligenten Ordner “Duplikate” anzuweisen, seine Inhalte täglich oder am besten gleich selbstständig zu löschen.

mmhh: Als ich jetzt die Regel für den Ordner gesendete Mails gelöscht habe, klappts mit der Anzeige nur einer Mail.
Warum ist das Ganze so kompliziert und geht nur über Gut Glück oder sonderbare Umwege?? :question:

Wenn mich nächste Woche jemand fragt, wie ich das zum laufen gebracht habe, kann ich nur mit den Schultern zucken.
Gibts denn da nichts Anwenderfreundlicheres? :arrow_right:

Das Script an sich erzeugt keine Duplikate. Wird es denn von mehreren Regeln verwendet, die sich eventuell überschneiden? Ansonsten käme nur noch in Frage, dass die Regel mit denselben Emails mehrfach von Apple Mail ausgeführt wird.

Hallo,
da steh ich wieder nu mit meinem Talent.
Obiges Script habe ich angewandt, um meine Mails automatisch in die Datenbank von DT abzulegen.
Was mir unter Mojave Os nicht gelingen mag, daß dieses Script mir, nach einer erstellten Regel ,
auch in den passenden Unterordner ablegt, sondern alles in die Inbox des Hauptordners.
Bsp.: Ich habe eine Mail Adresse (kaufen@t-online.de) für Stromanbieter, Amazon und Internetanbieter angegeben. Damit ich ein bisschen den Durchblick behalte, habe ich in diesem Account jeweils drei Unterordner erstellt und lasse per Regel die ankommenden Mails dort ablegen.
Bei High Sierra hat er auch dies auch in DT passend abgelegt.

Wie kann man das Script soweit anpassen, daß das auch weiterhin klappt?

Gruß
Rippchen mit Kraut

Hier noch mal das Script:

– POSIX path of destination database. Global inbox is used if not specified.
property pDatabasePath : “/pfad/zu/meiner/Datenbank”

– 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
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
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}
              
              -- Location of message
              set theMessageLocation to "/"
              try
                 set theMailbox to mailbox of theMessage
                 repeat while theMailbox is not missing value
                    set theName to name of theMailbox
                    set theMessageLocation to "/" & (theName as string) & theMessageLocation
                    set theMailbox to container of theMailbox
                 end repeat
              end try
              set theMessageLocation to "/Apple Mail" & theMessageLocation
           end tell
           
           set numAttachments to count of mail attachments of theMessage
           if theSubject is equal to "" then set theSubject to pNoSubjectString
           
           tell application id "DNtp"
              set message_group to create location theMessageLocation in destination_database
              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
              if numAttachments > 0 then set attachment_group to create location theMessageLocation & "/Attachments" in destination_database
           end tell
           
           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 attachment_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

Stelle gerade fest, daß auch die Ablage in die Unterordner meiner Datenbank nicht geht.
Es wird alles in den Eingang der Datenbank gelegt und nicht an den Unterordner weitergeleitet.
Habe hier das Hazel Script mit dem Einkopieren des Verweis des Unterordners genommen.

Wie kann man hier Abhilfe schaffen?

Gruß Rippchen mit Kraut

Haben Sie eventuell irgendwelche Anfragen seitens Mojave, ob z.B. Mail, Hazel oder DEVONthink andere Apps steuern dürfen, verneint? Die aktuellen Einstellungen sind unter Systemeinstellungen > Sicherheit > Automation zu finden.

Hallo,
es ist alles in der Systemsteuerung aktiviert und hat auch den jeweiligen Vollzugriff auf die Festplatte.
Mittlerweile funktioniert das Script mit der Eingabe des Verweises wieder einwandfrei.

Sorgenkind ist weiterhin Mail. Das Script macht was es will!
Weiterhin kann ich in einen Unterordner nicht direkt ablegen. Es wird immer in der Inbox des Account abgelegt.

Könnte man mit dem Script auch direkt einen Ordner ansprechen, so wie man es bei dem Script mit der Eingabe des Verweises macht?

Was tun , sprach Zeus?

Gruß Rippchen

Das Ziel wird durch die Variable theMessageLocation festgelegt, standardmäßig wird dabei die Mailbox-Hierarchie in der Gruppe “Apple Mail” abgebildet. Das lässt sich natürlich anpassen, sollte sich aber durch das Upgrade auf Mojave nicht geändert haben.

Und wie müßte dann der Pfad in der MessageLocation aussehen?
Hab zwar etwas rumprobiert, aber die Ergebnisse sind nicht zielführend.
Auch die gleichzeitige gesonderte Ablage der Attachments als Unterordner funzt da nicht.

Was auch seltsam ist, daß wenn DTPO beendet ist, ich dann eine Mail bekomme, diese zwar automatisch abgelegt wird, jedoch nicht in meinen angegeben Zielordner, obwohl ich pfad/zu/meiner/Datenbank/name dt.Base angeben habe.Hier rutscht sie mal in jene oder diese Datenbank.
Ist DTPO geöffnet, gehts wunderbar??!!

Gruß
Rippche

Zunächst einmal müsste der Block…


set theMessageLocation to "/"
try
set theMailbox to mailbox of theMessage
repeat while theMailbox is not missing value
set theName to name of theMailbox
set theMessageLocation to "/" & (theName as string) & theMessageLocation
set theMailbox to container of theMailbox
end repeat
end try
set theMessageLocation to "/Apple Mail" & theMessageLocation

…entfernt werden, dann könnten Sie z.B. die Zeile…


set theMessageLocation to "/Gruppe1/Gruppe2"

…stattdessen einfügen, so dass die Emails in der Gruppe “Gruppe2” innerhalb von “Gruppe1” landen.

Und den Pfad haben Sie auch entsprechend angepasst und ist auch korrekt? Denn…

…das klingt so, als würde das Öffnen aufgrund eines fehlerhaften Pfades scheitern, so dass einfach die gerade aktuelle Datenbank verwendet wird.

sind denn jetzt die PDFs in den importierten Emails durchsuchbar?
wenn ja, muss ich hier auch tiefer einsteigen…das vermisse ich nämlich schmerzlich.