Revision 25a3242a
Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt
SL/BackgroundJob/SyncEmailFolder.pm | ||
---|---|---|
1 |
package SL::BackgroundJob::SyncEmailFolder; |
|
2 |
|
|
3 |
use strict; |
|
4 |
use warnings; |
|
5 |
|
|
6 |
use parent qw(SL::BackgroundJob::Base); |
|
7 |
|
|
8 |
use SL::IMAPClient; |
|
9 |
use SL::DB::Manager::EmailImport; |
|
10 |
|
|
11 |
sub sync_email_folder { |
|
12 |
my ($self) = @_; |
|
13 |
my $folder = $self->{job_obj}->data_as_hash->{folder}; |
|
14 |
|
|
15 |
my $imap_client = SL::IMAPClient->new(); |
|
16 |
|
|
17 |
my $email_import = $imap_client->update_emails_from_folder($folder); |
|
18 |
return unless $email_import; |
|
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; |
|
37 |
} |
|
38 |
|
|
39 |
sub run { |
|
40 |
my ($self, $job_obj) = @_; |
|
41 |
$self->{job_obj} = $job_obj; |
|
42 |
|
|
43 |
$self->delete_email_imports(); |
|
44 |
|
|
45 |
$self->sync_email_folder(); |
|
46 |
|
|
47 |
return; |
|
48 |
} |
|
49 |
|
|
50 |
1; |
|
51 |
|
|
52 |
__END__ |
|
53 |
|
|
54 |
=encoding utf8 |
|
55 |
|
|
56 |
=head1 NAME |
|
57 |
|
|
58 |
SL::BackgroundJob::SyncEmailFolder - Background job for syncing emails from a folder |
|
59 |
|
|
60 |
=head1 SYNOPSIS |
|
61 |
|
|
62 |
This background job is used to sync emails from a folder. It can be used to sync |
|
63 |
emails from a folder on a regular basis for multiple folders. The folder to sync |
|
64 |
is specified in the data field 'folder' of the background job, by default the |
|
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. |
|
67 |
|
|
68 |
=head1 BUGS |
|
69 |
|
|
70 |
Nothing here yet. |
|
71 |
|
|
72 |
=head1 AUTHOR |
|
73 |
|
|
74 |
Tamino Steinert E<lt>tamino.steinert@tamino.stE<gt> |
|
75 |
|
|
76 |
=cut |
SL/BackgroundJob/SyncEmailInbox.pm | ||
---|---|---|
1 |
package SL::BackgroundJob::SyncEmailInbox; |
|
2 |
|
|
3 |
use strict; |
|
4 |
use warnings; |
|
5 |
|
|
6 |
use parent qw(SL::BackgroundJob::Base); |
|
7 |
|
|
8 |
use SL::IMAPClient; |
|
9 |
use SL::DB::Manager::EmailImport; |
|
10 |
|
|
11 |
sub sync_email_folder { |
|
12 |
my ($self) = @_; |
|
13 |
my $folder = $self->{job_obj}->data_as_hash->{folder}; |
|
14 |
|
|
15 |
my $imap_client = SL::IMAPClient->new(); |
|
16 |
|
|
17 |
my $email_import = $imap_client->update_emails_from_folder($folder); |
|
18 |
return unless $email_import; |
|
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; |
|
37 |
} |
|
38 |
|
|
39 |
sub run { |
|
40 |
my ($self, $job_obj) = @_; |
|
41 |
$self->{job_obj} = $job_obj; |
|
42 |
|
|
43 |
$self->delete_email_imports(); |
|
44 |
|
|
45 |
$self->sync_email_folder(); |
|
46 |
|
|
47 |
return; |
|
48 |
} |
|
49 |
|
|
50 |
1; |
|
51 |
|
|
52 |
__END__ |
|
53 |
|
|
54 |
=encoding utf8 |
|
55 |
|
|
56 |
=head1 NAME |
|
57 |
|
|
58 |
SL::BackgroundJob::SyncEmailFolder - Background job for syncing emails from a folder |
|
59 |
|
|
60 |
=head1 SYNOPSIS |
|
61 |
|
|
62 |
This background job is used to sync emails from a folder. It can be used to sync |
|
63 |
emails from a folder on a regular basis for multiple folders. The folder to sync |
|
64 |
is specified in the data field 'folder' of the background job, by default the |
|
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. |
|
67 |
|
|
68 |
=head1 BUGS |
|
69 |
|
|
70 |
Nothing here yet. |
|
71 |
|
|
72 |
=head1 AUTHOR |
|
73 |
|
|
74 |
Tamino Steinert E<lt>tamino.steinert@tamino.stE<gt> |
|
75 |
|
|
76 |
=cut |
Auch abrufbar als: Unified diff
BJ: Email Ordner synchronisieren umbenannt zu SyncEmailFolder
Dies trifft die Aufgabe besser.