Rt-mailgate change custom field

Hello,

Is there a way to change the custom field of a ticket when generated with rt-mailgate?

I have different email addresses pulled with pop3 through fetchmail and rt-mailgate, all are forwarded to different queues (as answer and comment)
In addition to the default email address of one queue, I would like to add an address with defined custom field.
Here you find a snippet from my fetchmail config:
poll mailserver protocol pop3
username “username” password "password"
mda "/usr/bin/rt-mailgate --queue queuename --action comment --url http://localhost/rt/"
no keep
;

The emails are sent from customers, so I cannot handle with special code in subject or content, because no customer would write this.
However I already have a scrip for detecting custom field from subject, so maybe one possible workaround would be to change the subject of the mail with some script, maybe with fetchmail, before processing rt-mailgate – but I also don’t know how to do this.

does anyone of you have an idea how to solve this?

Thanks very much!

Best Regards
Bernhard

I’m not quite sure what you’re asking for, but as far as I understand, you want to set a custom field based on an incoming email?

In that case, you can handle it with scrips, which fire on Ticket Create.

yes, I want to change a custom field based on an email, precisely: by the address the email was sent to.
so if a customer sends the mail to test1@asdf.com, the custom field is unchanged, if the email is sent to test2@asdf.com the custom field should be changed
both email addresses are forwarded to the same Queue.

I know about scrips but I don’t know how to detect the recipient mail address.

I think the condition should be something like "if recipient address = test2@asdf.com"
and the preparation code is changing the custom field (for this I know the syntax).

I just don’t know how to detect the recipient of the mail, I only found about the requestor mail address.

  my $trans = $self->TransactionObj;
  my $attachments = $trans->Attachments->ItemsArrayRef();
  my $recv_addr;
  
  for my $attach (@$attachments) {
      $recv_addr = $attach->GetHeader('recv_addr') if defined $attach->GetHeader('recv_addr');
 }

The above code snippet parse the headers, and fetches the receiving address. Of course, you’ll have to substitute recv_addr with the actual header in the emails RT receives, but I guess you’ll be good with either the from or envelope-to header.

now I took some time for testing, but I could not manage to get it working.

I understand your code and everything, I just don’t understand why it is not working.

I think the scrip is not able to catch the attachments. for exampleI tried

my $trans = $self->TransactionObj;
my $attachments = $trans->Attachments->ItemsArrayRef();
$RT::Logger->info($#attachments);

the output was
Global symbol "@attachments" requires explicit package name at (eval 2171) line 5.

or another thing I tested was
my $trans = $self->TransactiobObj; my $mail = $trans->Attachments->First->GetHeader; $RT::Logger->info($mail);

output was
Can't call method "GetHeader" on an undefined value at (eval 1902) line 6.

any idea?

I’m not sure I can help you, but for a very special case we use procmail and formail to add a “commandbyEmail” at the top of the mail.
It’s not very easy way to do it because procmail and formail is for (IMHO) regexp guru but well it’s work (in our case).

Regards.

Hello Albert_Smith,

thank you for this idea - this is exactly how I wanted to do first.
I think I can do what I need with regex, the only problem for me is: how can I use procmail?

In the moment, I use fetchmail to retrieve the mails and send to rt-mailgate.
how can I use procmail with this?

Can procmail retrieve the mails directly via pop3 and send to rt-mailgate?
Should I still use fetchmail and just send mails to procmail and procmail sends to rt-mailgate?
or can I put the procmail-command somewhere in fetchmail and still send to rt-mailgate from fetchmail?

Would be great if you could show me some configuration about this.

thanks a lot!

Le 04/07/2017 à 05:07:50+0000, Bernhard Eierschmalz a écrit

Hi,

thank you for this idea - this is exactly how I wanted to do first.
I think I can do what I need with regex, the only problem for me is: how can I
use procmail?

In the moment, I use fetchmail to retrieve the mails and send to rt-mailgate.
how can I use procmail with this?

Well I don’t know well fetchmail, but according to google it’s easy to make
procmail work with fetchmail.

Can procmail retrieve the mails directly via pop3 and send to rt-mailgate?
Should I still use fetchmail and just send mails to procmail and procmail sends
to rt-mailgate?
or can I put the procmail-command somewhere in fetchmail and still send to
rt-mailgate from fetchmail?

As I understand the workflow of fetchmail + procmail, it’s fetchmail who
« go get the mail » but instead to just write the content on the disk he
pass the mail to procmail.

Would be great if you could show me some configuration about this.

We using sendmail but should be similar to fetchmail + procmail. We got a
aliases file who contain :

rt: “|/usr/local/bin/procmail /usr/local/etc/procmailrc-rt”

and here some standard part of our procmailrc-rt

:0:

  • ^(To|Resent-To|Cc).ADDRESS.RT@FQDN
    | /usr/local/bin/rt-mailgate --queue QUEUE_NAME --action correspond --url https://RT_URL

:0:

  • ^(To|Resent-To|Cc).ADDRESS.RT-com@FQDN
    | /usr/local/bin/rt-mailgate --queue QUEUE_NAME --action comment --url https://RT_URL

here some thing for sympa (mailing list system), our use case is when some one ask for a mailing
list, the sympa daemon send email to « postmaster » who is aliased to RTUSER (the procmail-guy)
but we need the mail send to ADDRESS.RT otherwise RT going to complain (or
add postmaster as Cc) so we use this piece of procmail to rewrite the
header