#!/usr/bin/perl -wT
=head1 NAME

drop_sogo_response

=head1 DESCRIPTION

Drop email if it's a SOGo response for an appointment
and set it to NEEDS-ADCTION
Work around a problem in outlook dav where invitaions status are not correctly synced

=head1 AUTHOR

Daniel Berteaud <daniel@firewall-services.com>

=head1 LICENSE

GNU GPL v2 (GNU General Public License)

=cut


sub register {
  my ($self, $qp, %arg) = @_;
  $self->register_hook("data_post", "drop_sogo_response");
}


sub drop_sogo_response {
  my ($self, $transaction) = @_;
  my $type = $transaction->header->get('X-SOGo-Message-Type') or return DECLINED;
  $type =~ m/^calendar:invitation-reply$/ or return DECLINED;
  my $subj = $transaction->header->get('Subject') or return DECLINED;
  my $r = qr{=\?UTF-8\?q\?Sans_d=C3=A9cision};
  $subj =~ m/$r/m or return DECLINED;
  $self->log(LOGINFO, "SOGo response detected, droping email");
  return DENY;
}

