Revision 8f2e9c41
Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt
SL/BackgroundJob/SyncEmailInbox.pm | ||
---|---|---|
6 | 6 |
use parent qw(SL::BackgroundJob::Base); |
7 | 7 |
|
8 | 8 |
use SL::IMAPClient; |
9 |
use SL::DB::Manager::EmailImport; |
|
9 | 10 |
|
10 |
sub sync_email_inbox {
|
|
11 |
sub sync_email_folder {
|
|
11 | 12 |
my ($self) = @_; |
12 |
my $folder = $self->{job_obj}->data_as_hash->{folder} || 'INBOX';
|
|
13 |
my $folder = $self->{job_obj}->data_as_hash->{folder}; |
|
13 | 14 |
|
14 | 15 |
my $imap_client = SL::IMAPClient->new(); |
15 | 16 |
|
16 |
$imap_client->update_emails_from_folder($folder); |
|
17 |
my $email_import = $imap_client->update_emails_from_folder($folder); |
|
18 |
return unless $email_import; |
|
17 | 19 |
|
20 |
$self->{job_obj}->set_data(last_email_import_id => $email_import->id)->save; |
|
21 |
} |
|
22 |
|
|
23 |
sub delete_email_imports { |
|
24 |
my ($self) = @_; |
|
25 |
my $job_obj = $self->{job_obj}; |
|
26 |
|
|
27 |
my $email_import_ids_to_delete = |
|
28 |
$job_obj->data_as_hash->{email_import_ids_to_delete} || []; |
|
29 |
|
|
30 |
foreach my $email_import_id (@$email_import_ids_to_delete) { |
|
31 |
my $email_import = SL::DB::Manager::EmailImport->find_by(id => $email_import_id); |
|
32 |
next unless $email_import; |
|
33 |
$email_import->delete(cascade => 1); |
|
34 |
} |
|
35 |
|
|
36 |
$job_obj->set_data(email_import_ids_to_delete => [])->save; |
|
18 | 37 |
} |
19 | 38 |
|
20 | 39 |
sub run { |
21 | 40 |
my ($self, $job_obj) = @_; |
22 | 41 |
$self->{job_obj} = $job_obj; |
23 | 42 |
|
24 |
$self->sync_email_inbox(); |
|
43 |
$self->delete_email_imports(); |
|
44 |
|
|
45 |
$self->sync_email_folder(); |
|
25 | 46 |
|
26 | 47 |
return; |
27 | 48 |
} |
... | ... | |
34 | 55 |
|
35 | 56 |
=head1 NAME |
36 | 57 |
|
37 |
SL::BackgroundJob::SyncEmailInbox - Background job for syncing emails from a folder
|
|
58 |
SL::BackgroundJob::SyncEmailFolder - Background job for syncing emails from a folder
|
|
38 | 59 |
|
39 | 60 |
=head1 SYNOPSIS |
40 | 61 |
|
41 | 62 |
This background job is used to sync emails from a folder. It can be used to sync |
42 | 63 |
emails from a folder on a regular basis for multiple folders. The folder to sync |
43 | 64 |
is specified in the data field 'folder' of the background job, by default the |
44 |
folder 'INBOX' is used. Sub folders are separated by a forward slash,
|
|
45 |
e.g. 'INBOX/Archive'. Subfolders are not synced. |
|
65 |
folder 'base_folder' from IMAP client is used. Sub folders are separated by a
|
|
66 |
forward slash, e.g. 'INBOX/Archive'. Subfolders are not synced.
|
|
46 | 67 |
|
47 | 68 |
=head1 BUGS |
48 | 69 |
|
Auch abrufbar als: Unified diff
SyncEmailInbox: Id des letzten Imports ausgeben und Importe löschen