Leser: 2
|< 1 2 >| | 15 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#! /usr/bin/perl
use strict;
use warnings;
use CGI qw(:standard);
use Data::Dumper;
use CGI::Carp qw(fatalsToBrowser);
use lib qw(.);
use Mail::IMAPClient;
use Mail::Address;
print "Content-type: text/plain\n\n";#header(type => 'text/plain');
# general settings for connection
my $user = 'user';
my $server = 'imap.gmx.net';
my $password = 'password';
my $folder = 'INBOX';
my $target = '/path/to/target.file';
my $imap = Mail::IMAPClient->new(Server => $server,
User => $user,
Password => $password) or die $@;
my $mail_addresses = get_addresses($imap,$folder);
#print_to_file($target,$mail_addresses);
print $_,"\n" for(@$mail_addresses);
#------------------------------------------------------------------------------#
# Subroutines #
#------------------------------------------------------------------------------#
##
# parse e-mail-addresses from mail-headers
##
sub get_addresses{
my ($imap,$folder) = @_;
my @mail_addresses;
$imap->select($folder);
for my $folder($imap->messages()){
my $hashref = $imap->parse_headers($folder,"From");
my @from_addresses = Mail::Address->parse($hashref->{From}->[0]);
my $address = $from_addresses[0]->address();
push(@mail_addresses,$address);
}
return \@mail_addresses;
}# end get_addresses
##
# print the mail-addresses into a txt-file
##
sub print_to_file{
my ($target,$addresses) = @_;
open(my $fh,">>$target") or die $!;
for my $a(@$addresses){
print $fh $a,"\n";
}
close $fh;
}
my $body = $entity->bodyhandle;
1
2
3
4
5
6
7
for my $folder($imap->messages()){
my $hashref = $imap->parse_headers($folder,"From");
my @from_addresses = Mail::Address->parse($hashref->{From}->[0]);
my $address = $from_addresses[0]->address();
push(@mail_addresses,$address);
}
return \@mail_addresses;
my $hashref = $imap->parse_headers($folder,"From");
my @from_addresses = Mail::Address->parse($hashref->{From}->[0]);
my $address = $from_addresses[0]->address();
QuoteExample:
$Socket = $imap->Socket();
# or:
$imap->Socket($socket_fh);
The Socket method can be used to obtain the socket handle of the current connection (say, to do I/O on the connection that is not otherwise supported by Mail::IMAPClient) or to replace the current socket with a new handle (perhaps an SSL handle, for example).
If you supply a socket handle yourself, either by doing something like:
$imap=Mail::IMAPClient->new(Socket=>$sock, User => ... );
or by doing something like:
$imap=Mail::IMAPClient->new(User => $user, Password => $pass, Server => $host);
# blah blah blah
$imap->Socket($ssl);
then it will be up to you to establish the connection AND to authenticate, either via the the login manpage method, or the fancier the authenticate manpage, or, since you know so much anyway, by just doing raw I/O against the socket until you're logged in. If you do any of this then you should also set the the State manpage parameter yourself to reflect the current state of the object (i.e. Connected, Authenticated, etc).
|< 1 2 >| | 15 Einträge, 2 Seiten |