App-Lastmsg

 view release on metacpan or  search on metacpan

lib/App/Lastmsg.pm  view on Meta::CPAN

			my $date = str2time $msg->header_raw('Date');
			if (!exists $lastmsg{$id} || $lastmsg{$id} < $date) {
				$lastmsg{$id} = $date;
				$lastaddr{$id} = $addr;
			}
		}
	};

	for my $folder (@{$config->{inbox}}) {
		next unless -e $folder;
		say STDERR "Scanning $folder (inbox)" if $ENV{LASTMSG_DEBUG};
		my $folder = Email::Folder->new($folder);
		while (my $msg = $folder->next_message) {
			my ($from) = grep { /^from$/i } $msg->header_names;
			$from = $msg->header_raw($from);
			if ($ENV{LASTMSG_DEBUG}) {
				my ($mid) = grep { /^message-id$/i } $msg->header_names;
				say STDERR 'Processing ', $msg->header_raw($mid), " from $from";
			}
			$process_message->($msg, $from);
		}
	}

	for my $folder (@{$config->{sent}}) {
		next unless -e $folder;
		say STDERR "Scanning $folder (sent)" if $ENV{LASTMSG_DEBUG};
		my $folder = Email::Folder->new($folder);
		while (my $msg = $folder->next_message) {
			my @hdrs = grep { /^(?:to|cc|bcc)$/i } $msg->header_names;
			my @people;
			for my $hdr (@hdrs) {
				@people = (@people, split /,/, $msg->header_raw($hdr));
			}
			if ($ENV{LASTMSG_DEBUG}) {
				my ($mid) = grep { /^message-id$/i } $msg->header_names;
				say STDERR 'Processing ', $msg->header_raw($mid),
				  ' sent to ', join ',', @people;
			}
			$process_message->($msg, @people);
		}
	}

	my $idlen   = max map { length } keys %track;
	my $addrlen = max map { length } values %lastaddr;

	for (sort { $lastmsg{$b} <=> $lastmsg{$a} } keys %lastmsg) {



( run in 0.772 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )