Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision cc177bfe

Von Tamino Steinert vor 11 Monaten hinzugefügt

  • ID cc177bfe5a316b8a41916e109a41e83bd4bd53da
  • Vorgänger 99908669
  • Nachfolger 330343c7

IMAPClient: FIX: Suche nach Textteil der E-Mail

Unterschiede anzeigen:

SL/IMAPClient.pm
4 4
use warnings;
5 5
use utf8;
6 6

  
7
use Carp;
7 8
use IO::Socket::INET;
8 9
use IO::Socket::SSL;
9 10
use Mail::IMAPClient;
......
184 185
    }
185 186
  }
186 187

  
187
  my @email_parts = $email->parts; # get parts or self
188
  my $text_part = $email_parts[0];
188
  my $text_part;
189
  my %text_parts;
190
  _find_text_parts(\%text_parts, $email->parts);
191
  my @accepted_text_content_types = ('text/html', 'text/plain', '');
192
  $text_part ||= $text_parts{$_} for @accepted_text_content_types;
193
  confess "can't find body text in email" unless $text_part;
189 194
  my $body_text = $text_part->body_str;
190 195

  
191 196
  my %header_map = map { $_ => $email->header_str($_) } $email->header_names;
......
205 210
    my ($part) = @_;
206 211
    my $filename = $part->filename;
207 212
    if ($filename) {
208
      my $mime_type = $part->content_type;
209
      $mime_type =~ s/;.*//; # clean up mime_type
213
      my $mime_type = _cleanup_content_type($part->content_type);
210 214
      my $content = $part->body;
211 215
      my $attachment = SL::DB::EmailJournalAttachment->new(
212 216
        name      => $filename,
......
237 241
  return $email_journal;
238 242
}
239 243

  
244
sub _cleanup_content_type {
245
  my ($content_type) = @_;
246
  $content_type =~ s/\A\s+//; # Remove whitespaces at begin
247
  $content_type =~ s/\s+\z//; # Remove whitespaces at end
248
  $content_type =~ s/;.+//;   # For S/MIME, etc.
249
  return $content_type;
250
};
251

  
252
sub _find_text_parts {
253
  my ($text_parts, @parts) = @_;
254
  for my $part (@parts) {
255
    my $content_type = _cleanup_content_type($part->content_type);
256
    if ($content_type =~ m!^text/! or $content_type eq '') {
257
      $text_parts->{$content_type} ||= $part;
258
    }
259
    _find_text_parts($text_parts, $part->subparts);
260
  }
261
};
262

  
240 263
sub _parse_date {
241 264
  my ($self, $date) = @_;
242 265
  return '' unless $date;

Auch abrufbar als: Unified diff