Push-Nachrichten von MacTechNews.de
Würden Sie gerne aktuelle Nachrichten aus der Apple-Welt direkt über Push-Nachrichten erhalten?
Forum>Entwickler>Alle Emailadressen aus einem Emailkonto in Textfile?

Alle Emailadressen aus einem Emailkonto in Textfile?

aikonch31.03.0814:19
Gehört ein bisschen zu meiner andere Frage, hier allerdings mehr die Frage nach einer Idee oder gar Lösung.... Ich habe hier einen Emailaccount den ich per POP oder auch IMAP bzw. via Webmail abrufen kann und in welchem wohl um die 800 Mails sind. Nun sollte ich irgendwie jede VON Adresse auslesen und in Textfile schreiben können (Nein es geht hier nicht um SPAM!) doch wie mache ich das ausser manuell via Copy & Paste?
0

Kommentare

oefinger
oefinger31.03.0814:47
Perl? (Net::IMAP)
0
aikonch31.03.0815:01
oefinger.....ääähhh, sagt mir jetzt eher weniger....mit Perl ein IMAP Konto abrufen? Geht das? Gibt es da evt. ein bisschen Beispielcode, denn das dürfte meine Fähigkeiten bei weitem überschreiten.....
0
oefinger
oefinger31.03.0815:04


kannst dueigentlich übernehmen, musst nur schauen, ob die header-Informationen in der msg enthalten sind (dann einfach FROM rausparsen) oder ob man die extra bekommen kann
0
oefinger
oefinger31.03.0815:22
so etwa

use Net::IMAP::Simple;

$server = new Net::IMAP::Simple( 'someserver' );
$server->login( 'someuser', 'somepassword' );
    
$number_of_messages = $server->select( 'INBOX' );
foreach $msg ( 1..$number_of_messages ) {
        $fh = $server->getfh( $msg );
        foreach $msg_line(<$fh>){
            if( $msg_line =~m/From: *(\"*[^\"]*\"*) (*[^\@]+\@[^\.]*\.[a-zA-Z])/){
                print "$2\n";
            }
        }
        close $fh;
}

Ich kanns aktuell nicht testen, möglicherweise ist beim Pattern noch Feintuning nötig
0
aikonch01.04.0817:54
Hmmm, wohl doch komplexer....erhalte gleich beim Start:

./test.pl: line 1: use: command not found
./test.pl: line 3: syntax error near unexpected token `('
./test.pl: line 3: `$server = new Net::IMAP::Simple( 'aikon.ch' );'

Habe bisher mit Perl nur unter Sun gearbeitet, also hier keine Ahnung wo ich wie was ablegen muss....?!?
0
oefinger
oefinger01.04.0821:51
Ja, da fehlt ein bisschen was. Ich setz mich morgen mal dran und bastel das aus. In dem Pattern steckt eh noch ein Fehler drin.
0
oefinger
oefinger01.04.0822:41
Ok, Net::IMAP ist bei OS X nicht dabei. Also installieren, z.B. über

perl -MCPAN -e shell CPAN
und dann
cpan> install Net::IMAP::Simple
0
oefinger
oefinger01.04.0822:42
Dann das Skript:

#!/usr/bin/perl
use Net::IMAP::Simple;

$server = new Net::IMAP::Simple( 'someserver' );
$server->login( 'someuser', 'somepasswort' );
    
$number_of_messages = $server->select( 'INBOX' );

foreach $msg ( 1..$number_of_messages ) {
    $fh = $server->getfh( $msg );
    foreach $msg_line(<$fh>){
        if( $msg_line =~m/^From: (.+)/ ){
            print "$1\n";
        }
    }
    close $fh;
}
0
oefinger
oefinger01.04.0822:45
Das spukt nun Zeilen aus wie

xyz@apple.com

oder

"XYZ" xyz@apple.com

Da ich nicht weiss, wie du die Infos möchtest, musst du hier selber weitermachen
0
aikonch01.04.0822:57
Vielen Dank, wollte das via CPAN installieren, da kommen ein bisschen arg viele Fragen, wenn ich dann install starte erhalte ich:

CPAN.pm: Going to build C/CF/CFABER/Net-IMAP-Simple-1.17.tar.gz

Checking if your kit is complete...
Looks good
Writing Makefile for Net::IMAP::Simple
make: *** No rule to make target `/System/Library/Perl/5.8.8/darwin-thread-multi-2level/CORE/config.h', needed by `Makefile'. Stop.
/usr/bin/make -- NOT OK
Running make test
Can't test without successful make
Running make install
make had returned bad status, install seems impossible


Da habe ich wohl noch was falsch angegeben....doch ein bisschen viel komplexer als ich dachte.....
0
oefinger
oefinger01.04.0823:16
ok, perl ansatz gestorben

dann eben mit ApleScript

in Mail Konto anlegen und Nachrichten abrufen, alle selektieren und dann kommt man da irgendwie ran (hab von AppleScript keine Ahnung, ist nur so die Spur, der man folgen kann)
tell application "Mail"
    activate
    set theSelection to selection
    repeat with i from 1 to (number of items of theSelection)
        set theMessage to item i of theSelection
        set x to sender of theMessage
        
        --in x steht jetzt der (Ab)Sender
    end repeat
end tell
0
_mäuschen
_mäuschen02.04.0814:24

set CR to ASCII character 13
set allSender to {}
tell application "Mail"
 set theSelection to every message of inbox
 repeat with i from 1 to number of items of theSelection
  set theMessage to item i of theSelection
  set x to sender of theMessage
  set c to (offset of "<" in x) + 1
  set d to (offset of ">" in x) - 1
  set x to text from c to d of x
  if x contains "@" and ¬
   (offset of "." in x) is ((count of characters of x) - 2) or ¬
   (offset of "." in x) is ((count of characters of x) - 3) and ¬
   x is not in allSender then
   copy x to end of allSender
   copy CR to end of allSender
  end if
 end repeat
 set theText to allSender as string
 set fileName to "Alle Sender"
 tell application "TextEdit"
  set x to make new document with properties ¬
   {name:fileName, text:theText}
  set ptd to path to desktop as text
  set ptf to (ptd & fileName & ".txt")
  save x in file ptf
  close window 1
 end tell
end tell

0
oefinger
oefinger02.04.0814:29
_mäuschen

Hab ich es doch geahnt, dass du hier irgendwann auftauchst
0
aikonch02.04.0816:27
WOW, sehr cool, vielen herzlichen Dank....Apple Script kenne ich absolut nicht gefällt mir aber schon arg gut.....;)
Jetzt muss dieses File nur noch eines werden wo die Emails mit, getrennt und jede nur einmal vorkommt und alles ist perfekt, da werde ich mal ein bisschen austesten.
0
_mäuschen
_mäuschen02.04.0818:13
set allSender to {}
tell application "Mail"
 set theSelection to every message of inbox
 repeat with i from 1 to number of items of theSelection
  set theMessage to item i of theSelection
  set x to sender of theMessage
  set c to (offset of "<" in x) + 1
  set d to (offset of ">" in x) - 1
  set x to text from c to d of x
  if x contains "@" and ¬
   (offset of "." in x) is ((count of characters of x) - 2) or ¬
   (offset of "." in x) is ((count of characters of x) - 3) then
   if x is not in allSender then
    if i is greater than 1 then ¬
     copy "," to end of allSender
    copy x to end of allSender
   end if
  end if
 end repeat
 set theText to allSender as string
 set fileName to "Alle Sender"
end tell

tell application "TextEdit"
 set x to make new document with properties ¬
  {name:fileName, text:theText}
 set ptd to path to desktop as text
 set ptf to (ptd & fileName & ".txt")
 save x in file ptf
 close window 1
end tell


0
_mäuschen
_mäuschen02.04.0818:37


-- if x contains "@" and ¬
-- (offset of "." in x) is ((count of characters of x) - 2) or ¬
-- (offset of "." in x) is ((count of characters of x) - 3) then
-- end if

kannst Dir sparen, weil eh jeder Sender ein @ und . hat.

Es geht dann auch viel schneller


0
aikonch02.04.0822:38
_mäuschen, Du bist ja echt Hammer....sehr coole Sache. Wenn ich das ganze anschaue wollte ich das Inbox anpassen da ich ja mehrere Inboxen habe und will das nur bei einem Account anwenden. Ausserdem verstehe ich im Source nicht so recht wo das ganze "gemacht" wird in Sachen jede Email nur einmal, denn ich habe zusätzlich noch ein File wo auch noch einige Adressen vorhanden sind welche allenfalls auch noch gleich sind...Vielleicht kannst Du mir da auch nochmals ein bisschen auf die Sprünge helfen??
0
_mäuschen
_mäuschen03.04.0800:24

set allSender to {}
tell application "Mail"
 --set theSelection to every message of inbox
 set theSelection to ¬
  every message of mailbox "INBOX" of account "tempo23"
 repeat with i from 1 to number of items of theSelection
  set theMessage to item i of theSelection
  set x to sender of theMessage
  set c to (offset of "<" in x) + 1
  set d to (offset of ">" in x) - 1
  set x to text from c to d of x
  if x is not in allSender then
   if i is greater than 1 then ¬
    copy "," to end of allSender
   copy x to end of allSender
  end if
 end repeat
end tell

tell application "Finder"
 set theFile to choose file
 set fileItem to (open for access file theFile as string)
 try
  set fileContent to read fileItem
  close access fileItem
 on error
  close access fileItem
  display dialog "something went wrong"
 end try
end tell

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {","}
set theList to every text item of fileContent
set AppleScript's text item delimiters to astid

repeat with x in theList
 if x is not in allSender then
  copy "," to end of allSender
  copy x as text to end of allSender
 end if
end repeat

set fileName to "Alle Sender"
set theText to allSender as string

tell application "TextEdit"
 set f to make new document with properties ¬
  {name:fileName, text:theText}
 set ptd to path to desktop as text
 set ptf to (ptd & fileName & ".txt")
 save f in file ptf
 close window 1
end tell

0
aikonch03.04.0806:13
_mäuschen, wow das ist echt genial, vielen herzlichen Dank....funktioniert perfekt, werde mich nun dann noch ein bisschen den Code analysieren und hoffentlich das ein oder andere für die Zukunft verstehen!!
0

Kommentieren

Diese Diskussion ist bereits mehr als 3 Monate alt und kann daher nicht mehr kommentiert werden.