Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4c39335f

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID 4c39335febe115dfe9c39e9f1784645cb6a30036
  • Vorgänger a0b482c6
  • Nachfolger 3b77b3c7

BJ zum Belege synchronisieren angepasst, auch EmailJournal nutzen

Alle Emails in Unterordnern werden synchronisiert und Emaildateien zu
den Belegen gespeichert. Alle unter Ordner, die nicht zu offenen Belegen
gehören, werden gelöscht.

Unterschiede anzeigen:

SL/IMAPClient.pm
244 244
  }
245 245
}
246 246

  
247
sub update_email_files_for_all_records {
247
sub update_email_subfolders_and_files_for_records {
248 248
  my ($self) = @_;
249
  my $record_folder_path = $self->{base_folder};
249
  my $base_folder_path = $self->{base_folder};
250
  my $base_folder_string = $self->get_folder_string_from_path($base_folder_path);
250 251

  
251
  my $subfolder_strings = $self->{imap_client}->folders($record_folder_path)
252
  my $folder_strings = $self->{imap_client}->folders($base_folder_string)
252 253
    or die "Could not get folders via IMAP: $@\n";
253
  my @record_folder_strings = grep { $_ ne $record_folder_path }
254
    @$subfolder_strings;
254
  my @subfolder_strings = grep { $_ ne $base_folder_string } @$folder_strings;
255

  
256
  # Store all emails in journal
257
  my $email_import =
258
    $self->_update_emails_from_folder_strings($base_folder_path, \@subfolder_strings);
255 259

  
256
  foreach my $record_folder_string (@record_folder_strings) {
257
    my $ilike_folder_path = $self->get_ilike_folder_path_from_string($record_folder_string);
260
  # Store the emails to the records
261
  foreach my $subfolder_string (@subfolder_strings) {
262
    my $ilike_folder_path = $self->get_ilike_folder_path_from_string($subfolder_string);
258 263
    my (
259 264
      $ilike_record_folder_path, # is greedily matched
260 265
      $ilike_customer_number, # no spaces allowed
......
266 271
    my $record_type = $RECORD_FOLDER_TO_TYPE{$record_folder};
267 272
    next unless $record_type;
268 273

  
274
    # TODO make it generic for all records
269 275
    my $is_quotation = $record_type eq 'sales_quotation' ? 1 : 0;
270 276
    my $number_field = $is_quotation ? 'quonumber' : 'ordnumber';
271
    my $order = SL::DB::Manager::Order->get_first(
277
    my $record = SL::DB::Manager::Order->get_first(
272 278
      query => [
273 279
        and => [
274 280
          vendor_id => undef,
......
276 282
          $number_field => { ilike => $ilike_record_number },
277 283
        ],
278 284
    ]);
279
    next unless $order;
280

  
281
    $self->update_email_files_for_record($order);
285
    next unless $record;
286
    $self->update_email_files_for_record($record);
282 287
  }
288

  
289
  return ($email_import, \@subfolder_strings);
283 290
}
284 291

  
285 292
sub create_folder {
......
318 325
  return;
319 326
}
320 327

  
321
sub clean_up_record_folders {
328
sub clean_up_subfolders {
322 329
  my ($self, $active_records) = @_;
323 330
  my $record_folder_path = $self->{base_folder};
324 331

  
325
  $self->update_email_files_for_all_records();
326

  
327
  my $base_folder_string = $self->get_folder_string_from_path($record_folder_path);
328
  my @folders = $self->{imap_client}->folders($base_folder_string)
329
    or die "Could not get folders via IMAP: $@\n";
332
  my ($email_import, $synced_folders) =
333
    $self->update_email_subfolders_and_files_for_records();
330 334

  
331 335
  my @active_folders = map { $self->_get_folder_string_for_record($_) }
332 336
    @$active_records;
333
  push @active_folders, $base_folder_string;
334 337

  
335 338
  my %keep_folder = map { $_ => 1 } @active_folders;
336
  my @folders_to_delete = grep { !$keep_folder{$_} } @folders;
339
  my @folders_to_delete = grep { !$keep_folder{$_} } @$synced_folders;
337 340

  
338 341
  foreach my $folder (@folders_to_delete) {
339 342
    $self->{imap_client}->delete($folder)
340 343
      or die "Could not delete IMAP folder '$folder': $@\n";
341 344
  }
345

  
346
  return $email_import;
342 347
}
343 348

  
344 349
sub _get_folder_string_for_record {
......
501 506
  Updates the email files for a record. Checks which emails are missing and
502 507
  fetches these from the IMAP server.
503 508

  
504
=item C<update_email_files_for_all_records>
505
  
506
    Updates the email files for all records. Checks which emails are missing and
507
    fetches these from the IMAP server.
509
=item C<update_email_subfolders_and_files_for_records>
510

  
511
    Updates all subfolders and the email files for all records.
508 512

  
509 513
=item C<create_folder>
510 514

  
......
518 522
  The folder string is encoded in IMAP-UTF-7.
519 523

  
520 524
=item C<get_ilike_folder_path_from_string>
521
  
525

  
522 526
  Converts a folder string to a folder path. The folder path is like path
523 527
  on unix filesystem. The folder string is the path on the IMAP server.
524 528
  The folder string is encoded in IMAP-UTF-7. It can happend that
525 529
  C<get_folder_string_from_path> and C<get_ilike_folder_path_from_string>
526
  don't cancel each other out. This is because the IMAP server has a different
527
  separator than the unix filesystem. The changes are made so that a ILIKE
528
  query on the database works.
530
  don't cancel each other out. This is because the IMAP server can has a
531
  different Ieparator than the unix filesystem. The changes are made so that a
532
  ILIKE query on the database works.
529 533

  
530 534
=item C<create_folder_for_record>
531 535

  
......
534 538
  e.g. INBOX/1234 Testkunde/Angebot/123
535 539
  If the folder already exists, nothing happens.
536 540

  
537
=item C<clean_up_record_folders>
541
=item C<clean_up_subfolders>
538 542

  
539
  Gets a list of acitve records. First syncs the folders on the IMAP server with
540
  the corresponding record, by creating email files. Then deletes all folders
541
  which are not corresponding to an active record.
543
  Gets a list of acitve records. Syncs all subfolders and add email files to
544
  the records. Then deletes all subfolders which are not corresponding to an
545
  active record.
542 546

  
543 547
=item C<_get_folder_string_for_record>
544 548

  
......
556 560

  
557 561
=head1 BUGS
558 562

  
559
Nothing here yet.
563
The mapping from record to email folder is not bijective. If the record or
564
customer number has special characters, the mapping can fail. Read
565
C<get_ilike_folder_path_from_string> for more information.
560 566

  
561 567
=head1 AUTHOR
562 568

  

Auch abrufbar als: Unified diff