Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 0572a0b8

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID 0572a0b82de4d6e2409695705d29cbd46b761f6f
  • Vorgänger 81e922c2
  • Nachfolger d3846d7a

Imap-Sent verschiebe IMAP-Logik nach IMAPClient

Unterschiede anzeigen:

SL/IMAPClient.pm
51 51
  }
52 52
}
53 53

  
54
sub store_email_in_email_folder {
55
  my ($self, $email_string, $folder_path) = @_;
56
  $folder_path ||= $self->{base_folder};
57

  
58
  my $folder_string = $self->get_folder_string_from_path($folder_path);
59
  $self->{imap_client}->append_string($folder_string, $email_string)
60
    or die "Could not store email in folder '$folder_string': "
61
           . $self->{imap_client}->LastError() . "\n";
62
}
63

  
54 64
sub update_emails_from_folder {
55 65
  my ($self, $folder_path) = @_;
56 66
  $folder_path ||= $self->{base_folder};
SL/Mailer.pm
25 25

  
26 26
use IO::Socket::INET;
27 27
use IO::Socket::SSL;
28
use Mail::IMAPClient;
29 28
use Email::Address;
30 29
use Email::MIME::Creator;
31 30
use Encode;
......
41 40
use SL::Locale::String qw(t8);
42 41
use SL::Template;
43 42
use SL::Version;
43
use SL::IMAPClient;
44 44

  
45 45
use strict;
46 46

  
......
348 348
    || $::lx_office_conf{"sent_emails_in_imap/email/$user_email"}
349 349
    || $::lx_office_conf{sent_emails_in_imap}
350 350
    || {};
351
  return unless ($config->{enabled} && $config->{hostname});
352

  
353
  my $socket;
354
  if ($config->{ssl}) {
355
    $socket = IO::Socket::SSL->new(
356
      Proto    => 'tcp',
357
      PeerAddr => $config->{hostname},
358
      PeerPort => $config->{port} || 993,
359
    );
360
  } else {
361
    $socket = IO::Socket::INET->new(
362
      Proto    => 'tcp',
363
      PeerAddr => $config->{hostname},
364
      PeerPort => $config->{port} || 143,
365
    );
366
  }
367
  if (!$socket) {
368
    die "Failed to create socket for IMAP client: $@\n";
369
  }
351
  return unless ($config->{enabled});
370 352

  
371
  my $imap = Mail::IMAPClient->new(
372
    Socket   => $socket,
373
    User     => $config->{username},
374
    Password => $config->{password},
375
  ) or do {
376
    die "Failed to create IMAP Client: $@\n"
377
  };
353
  my $imap_client = SL::IMAPClient->new(%$config);
378 354

  
379
  $imap->IsAuthenticated() or do {
380
    die "IMAP Client login failed: " . $imap->LastError() . "\n";
381
  };
382

  
383
  my $separator =  $imap->separator();
384
  my $folder    =  $config->{folder} || 'Sent/Kivitendo';
385
  $folder       =~ s|/|${separator}|g;
386

  
387
  $imap->append_string($folder, $email_as_string) or do {
388
    my $last_error = $imap->LastError();
389
    $imap->logout();
390
    die "IMAP Client append failed: $last_error\n";
391
  };
355
  $imap_client->store_email_in_email_folder(
356
    $email_as_string,
357
    $config->{folder} ||'Sent/Kivitendo'
358
  );
392 359

  
393
  $imap->logout();
394 360
  return 1;
395 361
}
396 362

  

Auch abrufbar als: Unified diff