Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 814ba821

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID 814ba821969b16ab2268759fe436967dbbe5a91e
  • Vorgänger d6db8528

FIX: uidvalidity für Emailordner mit speichern

Unterschiede anzeigen:

SL/DB/MetaSetup/EmailJournal.pm
9 9
__PACKAGE__->meta->table('email_journal');
10 10

  
11 11
__PACKAGE__->meta->columns(
12
  body            => { type => 'text', not_null => 1 },
13
  email_import_id => { type => 'integer' },
14
  extended_status => { type => 'text', not_null => 1 },
15
  folder          => { type => 'text' },
16
  from            => { type => 'text', not_null => 1 },
17
  headers         => { type => 'text', not_null => 1 },
18
  id              => { type => 'serial', not_null => 1 },
19
  itime           => { type => 'timestamp', default => 'now()', not_null => 1 },
20
  mtime           => { type => 'timestamp', default => 'now()', not_null => 1 },
21
  recipients      => { type => 'text', not_null => 1 },
22
  sender_id       => { type => 'integer' },
23
  sent_on         => { type => 'timestamp', default => 'now()', not_null => 1 },
24
  status          => { type => 'enum', check_in => [ 'sent', 'send_failed', 'imported' ], db_type => 'email_journal_status', not_null => 1 },
25
  subject         => { type => 'text', not_null => 1 },
26
  uid             => { type => 'integer' },
12
  body               => { type => 'text', not_null => 1 },
13
  email_import_id    => { type => 'integer' },
14
  extended_status    => { type => 'text', not_null => 1 },
15
  folder             => { type => 'text' },
16
  folder_uidvalidity => { type => 'text' },
17
  from               => { type => 'text', not_null => 1 },
18
  headers            => { type => 'text', not_null => 1 },
19
  id                 => { type => 'serial', not_null => 1 },
20
  itime              => { type => 'timestamp', default => 'now()', not_null => 1 },
21
  mtime              => { type => 'timestamp', default => 'now()', not_null => 1 },
22
  recipients         => { type => 'text', not_null => 1 },
23
  sender_id          => { type => 'integer' },
24
  sent_on            => { type => 'timestamp', default => 'now()', not_null => 1 },
25
  status             => { type => 'enum', check_in => [ 'sent', 'send_failed', 'imported' ], db_type => 'email_journal_status', not_null => 1 },
26
  subject            => { type => 'text', not_null => 1 },
27
  uid                => { type => 'integer' },
27 28
);
28 29

  
29 30
__PACKAGE__->meta->primary_key_columns([ 'id' ]);
SL/IMAPClient.pm
88 88
      $self->{imap_client}->select($folder_string)
89 89
        or die "Could not select IMAP folder '$folder_string': $@\n";
90 90

  
91
      my $folder_uidvalidity = $self->{imap_client}->uidvalidity($folder_string)
92
        or die "Could not get UIDVALIDITY for folder '$folder_string': $@\n";
93

  
91 94
      my $msg_uids = $self->{imap_client}->messages
92 95
        or die "Could not get messages via IMAP: $@\n";
93 96

  
......
99 102
        WHERE ei.host_name = ?
100 103
          AND ei.user_name = ?
101 104
          AND ej.folder = ?
105
          AND ej.folder_uidvalidity = ?
102 106
SQL
103 107

  
104 108
      my $existing_uids = $dbh->selectall_hashref($query, 'uid', undef,
105
        $self->{hostname}, $self->{username}, $folder_string);
109
        $self->{hostname}, $self->{username}, $folder_string, $folder_uidvalidity);
106 110

  
107 111
      my @new_msg_uids = grep { !$existing_uids->{$_} } @$msg_uids;
108 112

  
......
114 118
        my $new_email_string = $self->{imap_client}->message_string($new_uid);
115 119
        my $email = Email::MIME->new($new_email_string);
116 120
        my $email_journal = $self->_create_email_journal(
117
          $email, $email_import, $new_uid, $folder_string
121
          $email, $email_import, $new_uid, $folder_string, $folder_uidvalidity
118 122
        );
119 123
        $email_journal->save();
120 124
      }
......
135 139
}
136 140

  
137 141
sub _create_email_journal {
138
  my ($self, $email, $email_import, $uid, $folder_path) = @_;
142
  my ($self, $email, $email_import, $uid, $folder_string, $folder_uidvalidity) = @_;
139 143

  
140 144
  my @email_parts = $email->parts; # get parts or self
141 145
  my $text_part = $email_parts[0];
......
167 171
  });
168 172

  
169 173
  my $email_journal = SL::DB::EmailJournal->new(
170
    email_import_id => $email_import->id,
171
    folder          => $folder_path,
172
    uid             => $uid,
173
    status          => 'imported',
174
    extended_status => '',
175
    from            => $email->header('From') || '',
176
    recipients      => $recipients,
177
    sent_on         => $date,
178
    subject         => $email->header('Subject') || '',
179
    body            => $body,
180
    headers         => $header_string,
181
    attachments     => \@attachments,
174
    email_import_id    => $email_import->id,
175
    folder             => $folder_string,
176
    folder_uidvalidity => $folder_uidvalidity,
177
    uid                => $uid,
178
    status             => 'imported',
179
    extended_status    => '',
180
    from               => $email->header('From') || '',
181
    recipients         => $recipients,
182
    sent_on            => $date,
183
    subject            => $email->header('Subject') || '',
184
    body               => $body,
185
    headers            => $header_string,
186
    attachments        => \@attachments,
182 187
  );
183 188

  
184 189
  return $email_journal;
sql/Pg-upgrade2/email_import.sql
1
-- @tag: email_import
2
-- @description: Email Journal für importierte E-Mails erweitern
3
-- @depends: release_3_8_0
4

  
5
CREATE TABLE email_imports (
6
  id              SERIAL    NOT NULL PRIMARY KEY,
7
  host_name       TEXT      NOT NULL,
8
  user_name       TEXT      NOT NULL,
9
  folder          TEXT      NOT NULL,
10
  itime           TIMESTAMP NOT NULL DEFAULT now()
11
);
12

  
13
ALTER TABLE email_journal ADD COLUMN email_import_id INTEGER REFERENCES email_imports(id);
14
ALTER TABLE email_journal ADD COLUMN folder          TEXT;
15
ALTER TABLE email_journal ADD COLUMN uid             INTEGER;
16
CREATE INDEX email_journal_folder_uid_idx ON email_journal (folder, uid);
17
-- NOTE: change status from text to enum and add 'imported'
18
CREATE TYPE email_journal_status AS ENUM ('sent', 'send_failed', 'imported');
19
ALTER TABLE email_journal DROP CONSTRAINT valid_status;
20
ALTER TABLE email_journal RENAME COLUMN status TO old_status;
21
ALTER TABLE email_journal ADD COLUMN status email_journal_status;
22
UPDATE email_journal SET status = 'sent'        WHERE old_status = 'ok';
23
UPDATE email_journal SET status = 'send_failed' WHERE old_status = 'failed';
24
ALTER TABLE email_journal ALTER COLUMN status SET NOT NULL;
25
ALTER TABLE email_journal DROP COLUMN old_status;
26

  
27

  
sql/Pg-upgrade2/email_journal_add_uidvalidity.sql
1
-- @tag: email_journal_add_uidvalidity
2
-- @description: Ordner uidvalidity für importierte E-Mails
3
-- @depends: release_3_8_0
4

  
5
ALTER TABLE email_journal ADD COLUMN folder_uidvalidity TEXT;
sql/Pg-upgrade2/email_journal_update.sql
1
-- @tag: email_import
2
-- @description: Email Journal für importierte E-Mails erweitern
3
-- @depends: release_3_8_0
4

  
5
CREATE TABLE email_imports (
6
  id              SERIAL    NOT NULL PRIMARY KEY,
7
  host_name       TEXT      NOT NULL,
8
  user_name       TEXT      NOT NULL,
9
  folder          TEXT      NOT NULL,
10
  itime           TIMESTAMP NOT NULL DEFAULT now()
11
);
12

  
13
ALTER TABLE email_journal ADD COLUMN email_import_id INTEGER REFERENCES email_imports(id);
14
ALTER TABLE email_journal ADD COLUMN folder          TEXT;
15
ALTER TABLE email_journal ADD COLUMN uid             INTEGER;
16
CREATE INDEX email_journal_folder_uid_idx ON email_journal (folder, uid);
17
-- NOTE: change status from text to enum and add 'imported'
18
CREATE TYPE email_journal_status AS ENUM ('sent', 'send_failed', 'imported');
19
ALTER TABLE email_journal DROP CONSTRAINT valid_status;
20
ALTER TABLE email_journal RENAME COLUMN status TO old_status;
21
ALTER TABLE email_journal ADD COLUMN status email_journal_status;
22
UPDATE email_journal SET status = 'sent'        WHERE old_status = 'ok';
23
UPDATE email_journal SET status = 'send_failed' WHERE old_status = 'failed';
24
ALTER TABLE email_journal ALTER COLUMN status SET NOT NULL;
25
ALTER TABLE email_journal DROP COLUMN old_status;
26

  
27

  

Auch abrufbar als: Unified diff