Revision f7c22a23
Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt
SL/IMAPClient.pm | ||
---|---|---|
341 | 341 |
return; |
342 | 342 |
} |
343 | 343 |
|
344 |
sub clean_up_imported_emails_from_folder { |
|
345 |
my ($self, $folder_path) = @_; |
|
346 |
$folder_path ||= $self->{base_folder}; |
|
347 |
|
|
348 |
my $folder_string = $self->get_folder_string_from_path($folder_path); |
|
349 |
$self->_clean_up_imported_emails_from_folder_strings([$folder_string]); |
|
350 |
} |
|
351 |
|
|
352 |
|
|
353 |
sub _clean_up_imported_emails_from_folder_strings { |
|
354 |
my ($self, $folder_strings) = @_; |
|
355 |
my $dbh = SL::DB->client->dbh; |
|
356 |
|
|
357 |
foreach my $folder_string (@$folder_strings) { |
|
358 |
$self->{imap_client}->select($folder_string) |
|
359 |
or die "Could not select IMAP folder '$folder_string': $@\n"; |
|
360 |
|
|
361 |
my $folder_uidvalidity = $self->{imap_client}->uidvalidity($folder_string) |
|
362 |
or die "Could not get UIDVALIDITY for folder '$folder_string': $@\n"; |
|
363 |
|
|
364 |
my $msg_uids = $self->{imap_client}->messages |
|
365 |
or die "Could not get messages via IMAP: $@\n"; |
|
366 |
|
|
367 |
my $query = <<SQL; |
|
368 |
SELECT uid |
|
369 |
FROM email_imports ei |
|
370 |
LEFT JOIN email_journal ej |
|
371 |
ON ej.email_import_id = ei.id |
|
372 |
WHERE ei.host_name = ? |
|
373 |
AND ei.user_name = ? |
|
374 |
AND ej.folder = ? |
|
375 |
AND ej.folder_uidvalidity = ? |
|
376 |
SQL |
|
377 |
|
|
378 |
my $existing_uids = $dbh->selectall_hashref($query, 'uid', undef, |
|
379 |
$self->{hostname}, $self->{username}, $folder_string, $folder_uidvalidity); |
|
380 |
|
|
381 |
my @imported_msg_uids = grep { $existing_uids->{$_} } @$msg_uids; |
|
382 |
|
|
383 |
next unless scalar @imported_msg_uids; |
|
384 |
|
|
385 |
$self->{imap_client}->delete_message(\@imported_msg_uids) |
|
386 |
or die "Could not delete messages via IMAP: $@\n"; |
|
387 |
} |
|
388 |
} |
|
389 |
|
|
344 | 390 |
sub clean_up_record_subfolders { |
345 | 391 |
my ($self, $active_records) = @_; |
346 | 392 |
|
Auch abrufbar als: Unified diff
IMAPClient: Funktion zum Aufräumen von importierten Emails hinzugefügt