1 # This module is part of debbugs, and is released
2 # under the terms of the GPL version 2, or any later version. See the
3 # file README and COPYING for more information.
4 # Copyright 2017 by Don Armstrong <don@donarmstrong.com>.
6 package Debbugs::DB::ResultSet::CorrespondentFullName;
10 Debbugs::DB::ResultSet::CorrespondentFullName - Correspondent table actions
25 use base 'DBIx::Class::ResultSet';
27 use Debbugs::DB::Util qw(select_one);
29 use Debbugs::Common qw(getparsedaddrs);
30 use Debbugs::DB::Util qw(select_one);
31 use Scalar::Util qw(blessed);
33 sub upsert_correspondent_id {
34 my ($self,$addr) = @_;
37 $full_addr = $addr->format();
43 search({full_addr => $addr,
45 {result_class => 'DBIx::Class::ResultClass::HashRefInflator',
49 return $rs->{correspondent};
51 if (not defined $addr) {
52 $addr = getparsedaddrs($full_addr);
54 my $email = $addr->address();
55 my $name = $addr->phrase();
57 $name =~ s/^\"|\"$//g;
58 $name =~ s/^\s+|\s+$//g;
62 my $ci = $self->result_source->schema->
63 select_one(<<'SQL',$addr,$addr);
65 INSERT INTO correspondent (addr) VALUES (?)
66 ON CONFLICT (addr) DO NOTHING RETURNING id
70 SELECT id FROM correspondent WHERE addr = ?
73 $self->result_source->schema->
74 select_one(<<'SQL',$ci,$full_addr,$name);
76 INSERT INTO correspondent_full_name (correspondent,full_addr,name)
77 VALUES (?,?,?) ON CONFLICT (correspondent,full_addr) DO UPDATE SET last_seen=NOW() RETURNING correspondent