Archive of articles classified as' "Apple Mail"

Back home

AppleMail: Sende Email als Attachment einer anderen…

12/02/2010
Ok, die Sinnfrage stelle ich mal nicht. Wenn jemand aber wie z.B. in Thunderbird eine Email nicht als Text, sondern die gesamte Email (Header inkl.) als Attachment verschicken möchte, der könnte eine dieser AppleScript-Funktionen nutzen, um das zu erreichen:
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

on create_mail_emlx_files_attachment_of_selection()

tell application "Mail"

-- get the mail selection

set myMessages to selection

--do it to every selected mail

repeat with m in myMessages

--get the folder where the emlx file is stored in

set mypath to quoted form of POSIX path of ((account directory of account of mailbox of m) as alias)

--get the id of that message (should be unique within each account)

set myid to id of m

--find the folder where this unique email (by id) is stored in

set myfolder to quoted form of (paragraph 1 of (do shell script "find " & mypath & " -name '" & myid & "*.emlx*' -exec dirname {} \\;"))

--create a compressed tar archive of this message and open this gzipped files with Apple Mail (-> attach it to a new message).

do shell script "cd " & myfolder & ";tar -rf " & myid & ".tar " & myid & "*.emlx*;gzip " & myid & ".tar;mv " & myid & ".tar.gz /tmp/;open -a /Applications/Mail.app /tmp/" & myid & ".tar.gz"

end repeat

end tell

end create_mail_emlx_files_attachment_of_selection


on create_mail_source_attachment_of_selection()

tell application "Mail"

-- get the mail selection

set myMessages to selection

--do it to every selected mail

repeat with m in myMessages

set myid to id of m

set mysource to quoted form of ((source of m) as text)

do shell script "cd /tmp/;echo " & mysource & "|cat>/tmp/" & myid & ".txt;gzip " & myid & ".txt;open -a /Applications/Mail.app " & myid & ".txt.gz"

end repeat

end tell

end create_mail_source_attachment_of_selection

No Comments

Mail-Regel-Skript: Attachments sichern

20/01/2010
Hier ein simples Skript, welches Anhänge von Emails in einem vordefinierten Ordner sichert. Das kann man an eine Mail-Regel hängen.
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

-- hubionmac.com 2010-01

-- script to be added to a Apple Mail rule

--saves attachmens of new mails into a folder

on perform_mail_action(info)

tell application "Mail"

tell application "Finder" to set mypath to (folder "Mail Attachments Saved" of desktop) as text

set theMessages to |SelectedMessages| of info

repeat with thisMessage in theMessages

try

repeat with a in (every mail attachment of thisMessage)

set current_a_name to name of a

set current_a_name to my checkname_with_pdf_suffix(current_a_name, mypath as alias, false)

save a in mypath & current_a_name

end repeat

on error msg

do shell script "echo " & quoted form of msg & " | cat>>~/Desktop/MailscriptErrorLog.txt"

end try

end repeat

end tell

end perform_mail_action



on checkname_with_pdf_suffix(n, D, looped)

tell application "Finder"

set thefiles to name of every item of (D as alias)

end tell

if thefiles contains n then

if looped = false then

set n to ((characters 1 through -5 of n) & " 1" & (characters -4 through -1 of n)) as text

my checkname_with_pdf_suffix(n, D, true)

else

set tmp to (last word of ((characters 1 through -5 of n) as text) as integer)

set tmpcount to (count of characters of (tmp as text)) + 5

set tmp to tmp + 1

set n to ((characters 1 through (-1 * tmpcount) of n) & tmp & (characters -4 through -1 of n)) as text

my checkname_with_pdf_suffix(n, D, true)

end if

else

return n

end if

end checkname_with_pdf_suffix

8 Comments

Mails ins Postfach bewegen… 2.0

7/12/2009
Ist jetzt zwar nicht mehr ganz so simpel und "elegant" wie die erste Version, dafür kommt das Ding nun aber mit existierenden Unterordner und POP-Accounts (bisher nur IMAP) klar.
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

-- MoveMailTo

--  Created by Hubi on 16.06.2009

--Änderung vom 07.12.2009

-- ->Unterordner können nu auch als Ziel genutzt werden

-- ->POP Accounts bzw. lokale Ordner können nun auch angesprochen werden.

--  Copyright 2009 hubionmac.com. All rights reserved. ;-)

tell application "Mail"

set theSelection to selection

if theSelection ≠ {} then

try

set ac_name to (name of account of mailbox of (item 1 of theSelection))

set ac_typ to account type of account of mailbox of (item 1 of theSelection)

on error

--wenn eine Nachricht in einem lokalen Postfach ausgewählt wurde kann das nur schief gehen, also:

set ac_name to ""

set ac_typ to pop

end try

set t_mail to {}

if ac_typ = imap then

repeat with i from 1 to (count of every mailbox of account ac_name)

--set t_mail to t_mail & ((i & " " & name of mailbox i of account ac_name) as text)

set t_mail to t_mail & ((name of mailbox i of account ac_name & " (" & i & ")") as text)

end repeat

else if ac_typ = pop then

repeat with i from 1 to (count of every mailbox)

--set t_mail to t_mail & ((i & " " & name of mailbox i of account ac_name) as text)

set t_mail to t_mail & ((name of mailbox i & " (" & i & ")") as text)

end repeat

end if

set my_mailboxes to {"•••NEW•••"} & t_mail

set theaction to choose from list my_mailboxes default items {item 1 of my_mailboxes}

if theaction as text ≠ "false" then

if theaction as text = (item 1 of my_mailboxes) as text then

set new_mailboxname to text returned of (display dialog "New Mailbox" default answer "---New Mailbox ---")

if new_mailboxname as text ≠ "false" then

if ac_typ = imap then

tell account ac_name to set desti_box to (make new mailbox with properties {name:new_mailboxname})

else if ac_typ = pop then

make new mailbox with properties {name:new_mailboxname}

set desti_box to new_mailboxname

end if

end if

else

--set desti_box to mailbox ((first word of (theaction as text)) as integer) of account ac_name

if ac_typ = imap then

set desti_box to mailbox ((last word of (theaction as text)) as integer) of account ac_name

else if ac_typ = pop then

set desti_box to mailbox ((last word of (theaction as text)) as integer)

end if

end if

move theSelection to desti_box

end if

else

display dialog "Nix ausgewählt zum verschieben" giving up after 1

end if

end tell

3 Comments

Mail:Reine Text Email via Skript estellen

9/11/2009
Da gibt es doch glatt keinen Apple-Script-Befehlt zum Erstellen einer reinen Text-Email unter Apple Mail. An dem Punkt setzt dann GUI-Scripting an, das ausführen, was noch die zuvor ein Skript in einem Programm ausgeführt hat...
Nun, das hier als einfaches Beispiel, wie man eine Email in Apple Mail via Skript erstellt und anschließend über GUI-Skripting die Email in reinen Text umwandelt ( der letzte Schritt funnktioniert nur in einem dt. OS, da nach dem Namen des Menüpunktes gesucht wird!).
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

my new_mail("test_betreff", "keinevalideEmailAlsoGarNichtErstVersuchen@hubionmac.com", "Was ich schon immer mal schreibe wollte")


my switch_to_reinen_text()

on new_mail(email_betreff, toadresse, Mail_text)

tell application "Mail"

set newMessage to make new outgoing message with properties {subject:email_betreff as text}

tell newMessage

set visible to true

make new to recipient at beginning of to recipients ¬

with properties {address:toadresse}

set content to Mail_text

--make new cc recipient at beginning of cc recipients ¬

-- with properties {address:ccadresse}

end tell

end tell

end new_mail

on switch_to_reinen_text()

activate application "Mail"

tell application "System Events"

get system attribute "sysv"

if result is greater than or equal to 4144 then -- Mac OS X 10.3.0

if UI elements enabled then

tell application process "Mail"

if (name of menu item 11 of menu 1 of menu bar item 8 of menu bar 1) = "In reinen Text umwandeln" then

keystroke "t" using shift down & command down

end if

end tell

else

beep

display dialog "GUI Scripting is not enabled" & return & return & "Open System Preferences and check Enable Access for Assistive Devices in the Universal Access preference pane, then run this script again." with icon stop

if button returned of result is "OK" then

tell application "System Preferences"

activate

set current pane to pane "com.apple.preference.universalaccess"

end tell

end if

end if

else

beep

display dialog "This computer cannot run this script" & return & return & "The script uses GUI Scripting technology, which requires an upgrade to Mac OS X 10.3 Panther or newer." with icon caution buttons {"Quit"} default button "Quit"

end if

end tell

end switch_to_reinen_text

No Comments

Ausgewählten Text aus Safari als Email senden

19/09/2009
Mit cmd+i kann man ja in Safari die Website als HTML-Email verschicken. Mit dem Skript wird eine Email des ausgewählten Textes erstellt und an eine neue Email eingetragen:
Code zum markieren einmal anklicken

tell application "Safari"

tell document 1

set selected_text to do JavaScript "var txt = '';

if (window.getSelection)

{

    txt = window.getSelection();

}

else if (document.getSelection)

{

    txt = document.getSelection();

}

else if (document.selection)

{

    txt = document.selection.createRange().text;

}

else return;

"

set siteURL to URL

end tell

end tell

tell application "Mail"

activate

make new outgoing message with properties {visible:true, subject:"Something Interesting", content:"" & siteURL & return & return & selected_text}

end tell


No Comments

Mail Attachments sichern

17/09/2009
.emlx Dateien sind der Speicherort für Emails ab Mac OSX... ehm 10.5? Hier ein dirty-work-around zum automatischen Speichern von Anhängen in Apple Mail, da es direkt via AppleScript noch nicht möglich zu sein scheint siehe Update weiter unten (Automator zählt nicht ;-) ). Geht aber leider nur mit IMAP-Postfächern
Code zum markieren einmal anklicken

--© hubionmac.com 17.09.2009

--Stores attached pdfs (of an email received via IMAP) on your desktop

-- renames them by date received.... !!!MV overwrites existiting files!!!!

tell application "Mail"

set a to selection

end tell

repeat with s in a

tell application "Mail" to set current_date to date received of s

--convert applescript date to date string

set current_date to AppleScriptDateToString(current_date)

tell application "Mail"

--this works only on imap account, because there attachments are stored in a searate folder, not inline in .emlx-files

set attachments_path to do shell script "find ~/Library/Mail/ -name " & (id of s)

set current_attachments to do shell script "find " & quoted form of attachments_path & " -type f -iname \"*.pdf\" -exec mv {} ~/Desktop/" & current_date & ".pdf \\;"

end tell

get current_date

end repeat




on AppleScriptDateToString(a)

set b to current date

set monthnames to {}

repeat with i from 1 to 12

set month of b to i

set monthnames to monthnames & {(month of b) as text}

end repeat

set Y to (year of b)

set M to 0

repeat with t in monthnames

set M to M + 1

if t as text = (month of b) as text then

exit repeat

end if

end repeat

set M to Twodigits(M)

set D to Twodigits(day of b)

set hh to Twodigits(hours of b)

set mm to (minutes of b)

set ss to Twodigits(seconds of b)

--"2009-12-17 01:26:49"

--return Y & "-" & M & "-" & D & " " & hh & ":" & mm & ":" & ss as text

--"2009-12-17 01:28"

--return Y & "-" & M & "-" & D & " " & hh & ":" & mm as text

--"2009-12-17"

return Y & "-" & M & "-" & D as text

end AppleScriptDateToString

on Twodigits(a)

return (characters -2 through -1 of (("0" & a) as text)) as text

end Twodigits

UPDATE

Dieser Code ist deutlich besser, kommt mit bereits vergebenen Dateinamen klar und funktioniert auch mit jeder Art von Apple-Mail-Account =)
Code zum markieren einmal anklicken

(**

hubionmac.com 17.09.2009

save pdfs from seleceted email messages and save them in one folder

renames attachments by date received and from address like:

2009-12-09 from Steve Jobs <steve@apple.com>.pdf

2009-12-09 from Steve Jobs <steve@apple.com> 1.pdf

2009-12-09 from Steve Jobs <steve@apple.com> 2.pdf 


**)

set theAttachmentPath to (path to desktop) as text

tell application "Mail"

set a to selection

end tell

repeat with s in a

tell application "Mail"

set current_date to date received of s

set CurrentSender to sender of s

end tell

set current_date to AppleScriptDateToString(current_date)

tell application "Mail" to set Attached to mail attachments of s

repeat with ThisAttach in Attached

tell application "Mail" to set FileName to name of ThisAttach

if FileName ends with ".pdf" then

set FileName to current_date & " from " & CurrentSender & ".pdf" as text

set FileName to checkname_with_pdf_suffix(FileName, theAttachmentPath, false)

tell application "Mail" to save ThisAttach in theAttachmentPath & (FileName)

end if

end repeat

end repeat



on AppleScriptDateToString(a)

set b to a

set monthnames to {}

repeat with i from 1 to 12

set month of b to i

set monthnames to monthnames & {(month of b) as text}

end repeat

set Y to (year of b)

set M to 0

repeat with t in monthnames

set M to M + 1

if t as text = (month of b) as text then

exit repeat

end if

end repeat

set M to Twodigits(M)

set D to Twodigits(day of b)

set hh to Twodigits(hours of b)

set mm to (minutes of b)

set ss to Twodigits(seconds of b)

--"2009-12-17 01:26:49"

--return Y & "-" & M & "-" & D & " " & hh & ":" & mm & ":" & ss as text

--"2009-12-17 01:28"

--return Y & "-" & M & "-" & D & " " & hh & ":" & mm as text

--"2009-12-17"

return Y & "-" & M & "-" & D as text

end AppleScriptDateToString

on Twodigits(a)

return (characters -2 through -1 of (("0" & a) as text)) as text

end Twodigits



on checkname_with_pdf_suffix(n, D, looped)

tell application "Finder"

set thefiles to name of every item of (D as alias)

end tell

if thefiles contains n then

if looped = false then

set n to ((characters 1 through -5 of n) & " 1" & (characters -4 through -1 of n)) as text

checkname_with_pdf_suffix(n, D, true)

else

set tmp to (last word of ((characters 1 through -5 of n) as text) as integer)

set tmpcount to (count of characters of (tmp as text)) + 5

set tmp to tmp + 1

set n to ((characters 1 through (-1 * tmpcount) of n) & tmp & (characters -4 through -1 of n)) as text

checkname_with_pdf_suffix(n, D, true)

end if

else

return n

end if

end checkname_with_pdf_suffix

No Comments

Automatischer Zeilenumbruch nach x Zeichen in Apple Mail die 2.

2/09/2009

Nun, nach dem berechtigten Einwand von Alain M. Lafon in den Kommentaren und seinem Vorschlag mit fmt, habe ich mit der Hilfe von Rastafari bei Apfeltalk eine entsprechend schnellere und schlankere Version des Skriptes erstellt.
 Es führt die Shortcuts (copy&paste) selber aus. Also einfach nur noch in der Nachricht den Text auswählen, das Skript starten und fertig =)

try

tell application "Mail"

activate

display dialog "Umbruch nach ca. wieviel Zeichen?:" default answer "55"

set line_char_count to (text returned of the result) as integer

activate

tell application "System Events"

keystroke "c" using command down

end tell

set thetext to the clipboard

set myoutput to ""

repeat with a in every paragraph of thetext

set b to (do shell script "export LANG=UTF-8 && echo " & quoted form of a & " |fmt -p -w " & line_char_count)

set myoutput to myoutput & b & return

end repeat

set the clipboard to myoutput

tell application "System Events"

keystroke "v" using command down & shift down & option down

end tell

end tell

on error msg

error msg

end try

Man könnte natürlich den Loop in dem jede Zeile durchlaufen wird auch noch in den Shell-Script-Teil einbauen, das ist mit aber gerade einfach zu umständlich und so wie es jetzt ist, reicht mir die Geschwindigkeit auch aus =)

1 Comment

Mails in Postfach bewegen…

16/06/2009
Ist recht praktisch, wenn man es auf einen Shortcut legt. Dann kann man in Apple Mail ausgewählte Nachrichten innerhalb eines Accounts über die Tastatur verschieben =)
Code zum markieren einmal anklicken

-- MoveMailTo

--  Created by Hubi on 16.06.2009

--  Copyright 2009 hubionmac.com. All rights reserved. ;-)


tell application "Mail"

set theSelection to selection

if theSelection ≠ {} then

set ac_name to (name of account of mailbox of (item 1 of theSelection))

set my_mailboxes to {"•••NEW•••"} & (name of every mailbox of account ac_name)

set theaction to choose from list my_mailboxes default items {item 1 of my_mailboxes}

if theaction as text ≠ "false" then

if theaction as text = (item 1 of my_mailboxes) as text then

set new_mailboxname to text returned of (display dialog "New Mailbox" default answer "---New Mailbox ---")

if new_mailboxname as text ≠ "false" then

tell account ac_name to set desti_box to (make new mailbox with properties {name:new_mailboxname})

end if

else

set desti_box to mailbox (theaction as text) of account ac_name

end if

move theSelection to desti_box

end if

else

display dialog "Nix ausgewählt zum verschieben" giving up after 1

end if

end tell

3 Comments

Größe der Mailbox berechnen

8/05/2009
AppleScript Mailbox Size

Hm, wenn ich das richtig sehe, bekommt man in Apple Mail nicht wirklich die Größe einer einzelnen Mailbox heraus. Schon die Größe der Postfächer auf dem IMAP Server, aber bei POP3 wohl nur die der auf dem Server gespeicherten Emails. Jetzt könnte man natürlich in ~/Library/Mail einfach nachsehen oder sich die schlaflose Nacht mit einem AppleScript vertreiben:

Code zum markieren einmal anklicken

-- Mailbox Size Script


--  Created by Hubi on 08.05.2009

--  Copyright 2009 hubionmac.com. All rights reserved.

set c_date to do shell script "date '+%d.%m.%Y'"

set myoutput to "Mailstats vom " & c_date & return

do shell script "echo " & quoted form of myoutput & "| cat>/tmp/mailboxsize_" & c_date & ".txt"

tell application "Mail"

set accountlist to name of every account

set accountlist to (choose from list accountlist with multiple selections allowed)

if (count of accountlist) > 0 then

repeat with c_account in accountlist

set myoutput to "Account-Name: " & c_account

do shell script "echo " & quoted form of myoutput & "| cat>>/tmp/mailboxsize_" & c_date & ".txt"

set account_sum to 0

repeat with mb_i from 1 to count of every mailbox of account c_account

set c_mailbox_name to (name of mailbox mb_i of account c_account) as text

set mailbox_size_t to message size of every message of mailbox mb_i of account c_account

set mailbox_size to 0

repeat with s in mailbox_size_t

set mailbox_size to mailbox_size + s

end repeat

set account_sum to account_sum + mailbox_size

set mailbox_size to do shell script "echo 'scale=2; " & mailbox_size & "/1024/1024'|bc"

set myoutput to tab & c_mailbox_name & ": " & mailbox_size & " MB"

do shell script "echo " & quoted form of myoutput & "| cat>>/tmp/mailboxsize_" & c_date & ".txt"

end repeat

set account_sum to do shell script "echo 'scale=2; " & account_sum & "/1024/1024'|bc"

set myoutput to tab & "=================================="

do shell script "echo " & quoted form of myoutput & "| cat>>/tmp/mailboxsize_" & c_date & ".txt"

set myoutput to tab & "SUMME: " & account_sum & " MB"

do shell script "echo " & quoted form of myoutput & "| cat>>/tmp/mailboxsize_" & c_date & ".txt"

end repeat

end if

end tell


do shell script "open /tmp/mailboxsize_" & c_date & ".txt"

No Comments

Mail Account Switcher

13/03/2009
mailswitcher
Die Lösung mit dem Crontab war irgendwie zu unzuverlässig... man kann sich nie sicher sein, ob nicht ein Fahrrad-Unfall dazwischen kommen kann. Jetzt habe ich eine kleine Switch-Anwendung, die auf Knopfdruck einen Account ein oder ausschaltet, der entsprechende Account-Name steht einfach im Namen der Anwendung hinter dem Switch, für den Account "BlafaselMail" müsste man also das Programm in "Switch BlafaselMail.app" umbenennen =)
Download MailAccountSwitcher Version 1.0
No Comments