[Bps-public-commit] rt-extension-mailgate branch, master, updated. 9dd7282dac9616c61038879b0d7d3f3caaa2ea33
Chia-liang Kao
clkao at bestpractical.com
Wed Oct 6 10:28:50 EDT 2010
The branch, master has been updated
via 9dd7282dac9616c61038879b0d7d3f3caaa2ea33 (commit)
via b6ab50be6d607dccd37481dac4eef8e51c49acec (commit)
via fafd8459816da14a1d4de5ef15c761c0d0520eed (commit)
from e2bb290ebd77688a002697150690995636ee0c7a (commit)
Summary of changes:
html/Admin/Queues/MailGate.html | 123 +++++++++++++++++++++++++++++++--------
lib/RT/Extension/MailGate.pm | 24 +++++++-
2 files changed, 121 insertions(+), 26 deletions(-)
- Log -----------------------------------------------------------------
commit fafd8459816da14a1d4de5ef15c761c0d0520eed
Author: Chia-liang Kao <clkao at clkao.org>
Date: Wed Oct 6 20:58:25 2010 +0800
the actual message testing bits.
diff --git a/html/Admin/Queues/MailGate.html b/html/Admin/Queues/MailGate.html
index 758a592..7ad1125 100644
--- a/html/Admin/Queues/MailGate.html
+++ b/html/Admin/Queues/MailGate.html
@@ -1,3 +1,24 @@
+<style type="text/css" media="screen">
+span.mail-action {
+ float: left;
+ width: 100px;
+ color: red;
+}
+span.mail-from {
+ float: left;
+ width: 300px;
+}
+
+span.mail-subject {
+ float: left;
+ width: 200px;
+}
+
+span.mail-behaviour {
+ float: left;
+}
+</style>
+
<& /Admin/Elements/Header, Title => $title &>
<& /Admin/Elements/QueueTabs, id => $QueueObj->id,
QueueObj => $QueueObj,
@@ -41,13 +62,25 @@ Account:
Mailbox:
<input type="text" name="mailbox" value="<% $ARGS{mailbox} || 'INBOX' %>">
Matched address:
-<input type="text" name="matched_address" value="<% $ARGS{matched_address} || '*' %>">
+<input type="text" name="matched_address" value="<% $ARGS{matched_address} || '.*' %>">
<& /Elements/Submit, Name => "TestMailConfig", Label => loc('Test Config') &>
+<& /Elements/Submit, Name => "CreateAndTestMailConfig", Label => loc('Create a Test Mail and Test Config') &>
% if ($TestConfigResults) {
-<div class="error"><% $TestConfigResults->{Error} %></div>
-<div><% Dumper($TestConfigResults->{Content}) %></div>
+<div class="error"><% $TestConfigResults->{Error} || '' %></div>
+<div>
+% unless (@{$TestConfigResults->{Content}}) {
+<div>No message for testing</div>
+% }
+% for my $res (@{$TestConfigResults->{Content}}) {
+<span class="mail-action"><% $res->{action} %></span>
+<span class="mail-from"><% $res->{message}->header('From') %></span>
+<span class="mail-from"><% $res->{message}->header('Subject') %></span>
+<span class="mail-behaviour"><% $res->{delete} ? "Message will be deleted after fetch" : "Message will be marked as seen after fetch" %></span>
+<div class="clear">
+% }
+</div>
% }
<& /Elements/Submit, Name => "SaveMailConfig", Label => loc('Save Changes') &>
@@ -127,14 +160,14 @@ if ($ARGS{SaveMailConfig}) {
}
-if ($ARGS{TestMailConfig}) {
+if ($ARGS{TestMailConfig} || $ARGS{CreateAndTestMailConfig}) {
my ($opt) = grep { $_->{name} eq $new_mail_config->{account} } map { $_->Content } @$MailAccounts;
-delete $opt->{expunge};
- my $imap = eval { RT::Extension::MailGate->imap_from_opt($opt) };
- if ($imap) {
-
-my $data = <<'EOF';
+ delete $opt->{expunge};
+ if ($ARGS{CreateAndTestMailConfig}) {
+ my $imap = eval { RT::Extension::MailGate->imap_from_opt($opt) };
+ if ($imap) {
+ my $data = <<'EOF';
From: rt at example.com
To: contact at example.com
Subject: This is a test message!
@@ -142,19 +175,21 @@ Subject: This is a test message!
This is a automated generated test message for configuring your rt mail gateway.
EOF
- RT::Extension::MailGate->append_message($imap, "INBOX", $data);
-
+ RT::Extension::MailGate->append_message($imap, "INBOX", $data);
+ }
+ }
RT::Extension::MailGate->fetch_imap(
sub {
my $es = shift;
+ my $action = RT::Extension::MailGate->mail_action($new_mail_config, $opt, $es);
push @{$TestConfigResults->{Content} ||= []}, { message => $es,
- action => '....' };
+ action => $action,
+ $action ? ( delete => $opt->{delete} ) : () };
return 0;
}, $opt);
- }
- else {
- $TestConfigResults->{Error} = $@;
- }
+}
+else {
+ $TestConfigResults->{Error} = $@;
}
</%init>
diff --git a/lib/RT/Extension/MailGate.pm b/lib/RT/Extension/MailGate.pm
index f940555..aba648f 100644
--- a/lib/RT/Extension/MailGate.pm
+++ b/lib/RT/Extension/MailGate.pm
@@ -24,6 +24,11 @@ sub append_message {
$imap->put($mailbox, $msg);
}
+sub mail_action {
+ my ($self, $mail_config, $opt, $mail) = @_;
+ $mail->header('To') =~ $mail_config->{matched_address} ? $mail_config->{action} : 'Skip';
+}
+
sub fetch_imap {
my ($self, $cb, $opt) = @_;
commit b6ab50be6d607dccd37481dac4eef8e51c49acec
Author: Chia-liang Kao <clkao at clkao.org>
Date: Wed Oct 6 22:11:17 2010 +0800
actual dispatch
diff --git a/html/Admin/Queues/MailGate.html b/html/Admin/Queues/MailGate.html
index 7ad1125..bc2de15 100644
--- a/html/Admin/Queues/MailGate.html
+++ b/html/Admin/Queues/MailGate.html
@@ -1,12 +1,17 @@
<style type="text/css" media="screen">
span.mail-action {
float: left;
- width: 100px;
+ width: 200px;
color: red;
}
span.mail-from {
float: left;
- width: 300px;
+ width: 200px;
+}
+
+span.mail-to {
+ float: left;
+ width: 200px;
}
span.mail-subject {
@@ -30,12 +35,17 @@ span.mail-behaviour {
<h1>Mail Configuration</h1>
% if ($QueueMailConfig) {
- my ($comment) = $QueueObj->Attributes->Named( 'MailGateConfig-Comment' );
- my ($correspond) = $QueueObj->Attributes->Named( 'MailGateConfig-Correspond' );
-# { account => 'foo', mailbox => 'INBOX', matched_address => '*', }
+% for (@$QueueMailConfig) {
+<form method="post">
+% my $cfg = $_->Content;use Data::Dumper;
+<input type="submit" name="remove-<% $_->Id %>" value="Delete">
+<div><% Dumper($cfg) %></div>
+</form>
+% }
% }
% else {
No Configuration yet
+% }
<h2>Add a new configuration:</h2>
% if (!@$MailAccounts) {
<p>
@@ -48,6 +58,7 @@ Must configure mail accounts first.
Action:
<select name="action">
+<option value=""></option>
<option value="Correspond" <% $ARGS{action} && $ARGS{action} eq 'Correspond' ? 'selected' : '' %>>Correspond</option>
<option value="Comment" <% $ARGS{action} && $ARGS{action} eq 'Comment' ? 'selected' : '' %>>Comment</option>
</select>
@@ -65,6 +76,10 @@ Matched address:
<input type="text" name="matched_address" value="<% $ARGS{matched_address} || '.*' %>">
<& /Elements/Submit, Name => "TestMailConfig", Label => loc('Test Config') &>
+To: <input type="text" name="TestMailTo" value="<% $ARGS{TestMailTo} || $QueueObj->CorrespondAddress %>">
+Cc: <input type="text" name="TestMailCc" value="<% $ARGS{TestMailCc} || '' %>">
+Bcc: <input type="text" name="TestMailBcc" value="<% $ARGS{TestMailBcc} || '' %>">
+Subject: <input type="text" name="TestMailSubject" value="<% $ARGS{TestMailSubject} || 'a test message for queue '.$QueueObj->Name %>">
<& /Elements/Submit, Name => "CreateAndTestMailConfig", Label => loc('Create a Test Mail and Test Config') &>
% if ($TestConfigResults) {
@@ -76,7 +91,8 @@ Matched address:
% for my $res (@{$TestConfigResults->{Content}}) {
<span class="mail-action"><% $res->{action} %></span>
<span class="mail-from"><% $res->{message}->header('From') %></span>
-<span class="mail-from"><% $res->{message}->header('Subject') %></span>
+<span class="mail-to"><% $res->{message}->header('To') %></span>
+<span class="mail-subject"><% $res->{message}->header('Subject') %></span>
<span class="mail-behaviour"><% $res->{delete} ? "Message will be deleted after fetch" : "Message will be marked as seen after fetch" %></span>
<div class="clear">
% }
@@ -88,7 +104,7 @@ Matched address:
</form>
-% }
+
<h1>Available mail accounts</h1>
% for (@$MailAccounts) {
@@ -128,7 +144,6 @@ if ($QueueObj->id) {
Abort(loc("Queue [_1] not found",$id));
}
-my $QueueMailConfig;
my $TestConfigResults;
if (my @remove = map { m/remove-(.*)/ ? $1 : () } keys %ARGS) {
my $attr = RT::Attribute->new($session{'CurrentUser'});
@@ -156,10 +171,32 @@ my $MailAccounts = [ $RT::System->Attributes->Named( 'ExternalMailAccounts' ) ];
my $new_mail_config = { map { $_ => $ARGS{$_} } qw(action account mailbox matched_address) };
-if ($ARGS{SaveMailConfig}) {
+my @mailcfg;
+if ($ARGS{TestMailConfig} || $ARGS{CreateAndTestMailConfig} || $ARGS{SaveMailConfig}) {
+ # XXX: check conflict:
+warn "==> loading / $new_mail_config->{action}";
+ @mailcfg = RT::Extension::MailGate->load_mailconfig( $new_mail_config->{account}, $new_mail_config->{mailbox} );
+
+ push @mailcfg, { %$new_mail_config, queue => $id } if $new_mail_config->{action};
+
+ if (scalar @mailcfg > 1 && grep {$_->{matched_address} eq '.*'} @mailcfg) {
+ push @results, loc("Conflicting matched_address for account [_1] mailbox [_2]", $new_mail_config->{account}, $new_mail_config->{mailbox});
+ delete $ARGS{TestMailConfig}; delete $ARGS{CreateAndTestMailConfig}; delete $ARGS{SaveMailConfig};
+ }
+}
+
+if ($ARGS{SaveMailConfig} && $new_mail_config->{action}) {
+
+ $QueueObj->AddAttribute(Name => 'MailGateConfig', Description => 'MailGate Config ', Content => $new_mail_config);
+ push @results, loc("Config for queue '[_1]' saved", $QueueObj->Name);
+ $ARGS{action} = '';
}
+my $QueueMailConfig = [ $QueueObj->Attributes->Named('MailGateConfig') ];
+
+
+
if ($ARGS{TestMailConfig} || $ARGS{CreateAndTestMailConfig}) {
my ($opt) = grep { $_->{name} eq $new_mail_config->{account} } map { $_->Content } @$MailAccounts;
@@ -167,30 +204,31 @@ if ($ARGS{TestMailConfig} || $ARGS{CreateAndTestMailConfig}) {
if ($ARGS{CreateAndTestMailConfig}) {
my $imap = eval { RT::Extension::MailGate->imap_from_opt($opt) };
if ($imap) {
- my $data = <<'EOF';
-From: rt at example.com
-To: contact at example.com
-Subject: This is a test message!
+ my $data = <<"EOF";
+From: rt\@example.com
+To: $ARGS{TestMailTo}
+Subject: $ARGS{TestMailSubject}
This is a automated generated test message for configuring your rt mail gateway.
EOF
RT::Extension::MailGate->append_message($imap, "INBOX", $data);
}
+ else {
+ $TestConfigResults->{Error} = $@;
+ }
}
RT::Extension::MailGate->fetch_imap(
sub {
my $es = shift;
- my $action = RT::Extension::MailGate->mail_action($new_mail_config, $opt, $es);
+ my $action = RT::Extension::MailGate->mail_action(\@mailcfg, $opt, $es);
push @{$TestConfigResults->{Content} ||= []}, { message => $es,
action => $action,
$action ? ( delete => $opt->{delete} ) : () };
return 0;
}, $opt);
}
-else {
- $TestConfigResults->{Error} = $@;
-}
+
</%init>
<%args>
diff --git a/lib/RT/Extension/MailGate.pm b/lib/RT/Extension/MailGate.pm
index aba648f..956bdc6 100644
--- a/lib/RT/Extension/MailGate.pm
+++ b/lib/RT/Extension/MailGate.pm
@@ -1,7 +1,7 @@
use warnings;
use strict;
-
package RT::Extension::MailGate;
+
our $VERSION = '0.1';
use Net::IMAP::Simple;
use Email::Simple;
@@ -18,6 +18,16 @@ sub imap_from_opt {
return $imap;
}
+sub load_mailconfig {
+ my ($self, $account, $mailbox) = @_;
+ my $attrs = RT::Attributes->new(RT->SystemUser);
+ $attrs->Limit(FIELD => 'ObjectType', OPERATOR=> '=', VALUE => 'RT::Queue');
+
+ grep { $_->{account} eq $account &&
+ $_->{mailbox} eq $mailbox
+ } map { { %{$_->Content}, queue => $_->ObjectId } } $attrs->Named( 'MailGateConfig' );
+}
+
sub append_message {
my ($self, $imap, $mailbox, $msg) = @_;
$imap->select($mailbox);
@@ -25,8 +35,15 @@ sub append_message {
}
sub mail_action {
- my ($self, $mail_config, $opt, $mail) = @_;
- $mail->header('To') =~ $mail_config->{matched_address} ? $mail_config->{action} : 'Skip';
+ my ($self, $mailcfg, $opt, $mail) = @_;
+ for (@$mailcfg) {
+ next unless $mail->header('To') =~ $_->{matched_address};
+ my $q = RT::Queue->new(RT->SystemUser);
+ $q->Load($_->{queue});
+ return "$_->{action} in Queue '@{[ $q->Name ]}'";
+#$self->loc("[_1] in Queue [_2]", $self->loc($_->{action}), $q->Name);
+ }
+ return 'Skip';
}
sub fetch_imap {
commit 9dd7282dac9616c61038879b0d7d3f3caaa2ea33
Author: Chia-liang Kao <clkao at clkao.org>
Date: Wed Oct 6 22:31:13 2010 +0800
cleanup
diff --git a/html/Admin/Queues/MailGate.html b/html/Admin/Queues/MailGate.html
index bc2de15..987bdcf 100644
--- a/html/Admin/Queues/MailGate.html
+++ b/html/Admin/Queues/MailGate.html
@@ -6,12 +6,12 @@ span.mail-action {
}
span.mail-from {
float: left;
- width: 200px;
+ width: 150px;
}
span.mail-to {
float: left;
- width: 200px;
+ width: 150px;
}
span.mail-subject {
@@ -93,7 +93,10 @@ Subject: <input type="text" name="TestMailSubject" value="<% $ARGS{TestMailSubje
<span class="mail-from"><% $res->{message}->header('From') %></span>
<span class="mail-to"><% $res->{message}->header('To') %></span>
<span class="mail-subject"><% $res->{message}->header('Subject') %></span>
-<span class="mail-behaviour"><% $res->{delete} ? "Message will be deleted after fetch" : "Message will be marked as seen after fetch" %></span>
+<span class="mail-behaviour"><% $res->{action} ne 'Skip'
+ ? $res->{delete} ? "Message will be deleted after fetch"
+ : "Message will be marked as seen after fetch"
+ : "Message will not be processed" %></span>
<div class="clear">
% }
</div>
@@ -174,10 +177,7 @@ my $new_mail_config = { map { $_ => $ARGS{$_} } qw(action account mailbox matche
my @mailcfg;
if ($ARGS{TestMailConfig} || $ARGS{CreateAndTestMailConfig} || $ARGS{SaveMailConfig}) {
- # XXX: check conflict:
-warn "==> loading / $new_mail_config->{action}";
@mailcfg = RT::Extension::MailGate->load_mailconfig( $new_mail_config->{account}, $new_mail_config->{mailbox} );
-
push @mailcfg, { %$new_mail_config, queue => $id } if $new_mail_config->{action};
if (scalar @mailcfg > 1 && grep {$_->{matched_address} eq '.*'} @mailcfg) {
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list