在fuglu插件中,我如何向退信的邮件发送自定义消息给发件人?

huangapple go评论61阅读模式
英文:

In fuglu plugin, how can I send custom message for bounced email back to sender?

问题

当邮件因某些策略被拒绝时,我想从插件中发送一条自定义消息,说明邮件被拒绝的原因。如何在 FUGLU 版本 0.10 中实现这一目标?例如,我已经创建了两个收件人列表,如下所示:

if allow_group_list:
    suspect.recipients = allow_group_list
    self._logger().info(
        '888 ==== allowed suspect.recipients: %s' %(suspect.recipients))

if deny_group_list:
    suspect.recipients = deny_group_list
    self._logger().info(
        '9999 ====== denied suspect.recipients: %s' %(suspect.recipients))
    self.send_bounce_message(suspect,deny_group_list,msubject)
    self._mark_bounce_sent(message_id, deny_group_list,msubject)
    return REJECT

return DUNNO

def send_bounce_message(self, suspect,mto,msubject):
    blockinfo = 'Please add the specific user and resend'
    queueid = suspect.get_tag('specificuser.bounce.queueid')
    #suspect.set_tag(mto_address,suspect.recipient)
    if queueid:
        self._logger().info(
            f'{suspect.id} already sent specific user block bounce '
            f'to {suspect.from_address} with queueid {queueid}')
    else: #tmm
        self._logger().info(f"{suspect.id} sending specific user block "
                            f"bounce to {suspect.from_address}")
        bounce = Bounce(self.config)
        queueid = bounce.send_template_file(suspect.from_address,
                                            self.template_bounce,
                                            suspect,
                                            {'blockinfo':blockinfo,
                                             'mto':mto,
                                             'msubject':msubject
                                            })
        suspect.set_tag('specificuser.bounce.queueid', queueid)

这在我的自定义插件中是否可能?因为据我所知,邮件只有一个返回值。上述代码同时向允许列表和拒绝列表中的收件人发送实际邮件,并向拒绝列表发送了一个退信。这个逻辑有什么问题吗?

另一个尝试的选项:

我尝试的是创建两个允许和拒绝收件人的简单列表。如果邮件是从拒绝列表中存在的发件人发送的,邮件应该以自定义消息弹回。使用了 Fuglu 1.2。
在 fuglu.conf 中的设置如下:

plugins=custom_msg
disablebounces=0
[PluginAlias]
custom_msg=custom_msg.CustomMessagePlugin

# custom_msg.py 包含插件代码:
from fuglu.shared import ScannerPlugin, DUNNO, DELETE, Suspect, REJECT

class CustomMessagePlugin(ScannerPlugin):
    def __init__(self, *args, **kwargs):
        ScannerPlugin.__init__(self, *args, **kwargs)
        self.allowed_recipients = ['test9@y.com']
        self.denied_recipients = ['test8@y.com','another@y.com']

    def examine(self, suspect):
        sender = suspect.from_address.lower()
        recipient = suspect.recipients[0].lower()

        if recipient in self.denied_recipients:
            # 发送弹回消息给发件人
            bounce_message = "Your email to {} has been rejected.".format(recipient)
            return REJECT, bounce_message
        else:
            return DUNNO

    def lint(self):
        return

    def __str__(self):
        return "Custom Plugin"

当从 another@y.com 发送的邮件发送到自己(即 another@y.com)时,不会收到弹回邮件。如何解决这个问题?是否有语法问题?在哪里可以获得有关在 fuglu 中自定义弹回的帮助?

英文:

When a mail gets REJECTED due to some policy, I would like to send out a custom message from the plugin stating the reason for bounce or mail reject. How can this be achieved using FUGLU. version 0.10 ? eg. I have created 2 lists of recipients as follows:

    if allow_group_list:
        suspect.recipients = allow_group_list
        self._logger().info(
            '888 ==== allowed suspect.recipients: %s' %(suspect.recipients))

    if deny_group_list:
        suspect.recipients = deny_group_list
        self._logger().info(
            '9999 ====== denied suspect.recipients: %s' %(suspect.recipients))
        self.send_bounce_message(suspect,deny_group_list,msubject)
        self._mark_bounce_sent(message_id, deny_group_list,msubject)
        return REJECT

    
    return DUNNO

def send_bounce_message(self, suspect,mto,msubject):
    blockinfo = 'Please add the specific user and resend'
    queueid = suspect.get_tag('specificuser.bounce.queueid')
    #suspect.set_tag(mto_address,suspect.recipient)
    if queueid:
        self._logger().info(
            f'{suspect.id} already sent specific user block bounce '
            f'to {suspect.from_address} with queueid {queueid}')
    else: #tmm
        self._logger().info(f"{suspect.id} sending specific user block "
                            f"bounce to {suspect.from_address}")
        bounce = Bounce(self.config)
        queueid = bounce.send_template_file(suspect.from_address,
                                            self.template_bounce,
                                            suspect,
                                            {'blockinfo':blockinfo,
                                             'mto':mto,
                                             'msubject':msubject
                                            })
        suspect.set_tag('specificuser.bounce.queueid', queueid)

Is this possible in my custom plugin. Because AFAIK a mail has only 1 return value. The above sends out the actual mail to both the recipients in allowed as well as denied list and sends out a bounce to the denied list. Anything wrong in this logic?
#======
#Another option tried:
What i tried was a simple: created 2 lists to allow and deny recipients. If mail is sent from sender who exists in the denied list, mail should bounce with custom message. Used Fuglu 1.2.
settings in** fuglu.conf:**

plugins=custom_msg
disablebounces=0
[PluginAlias]
custom_msg=custom_msg.CustomMessagePlugin

# custom_msg.py contains the plugin code:
from fuglu.shared import ScannerPlugin, DUNNO, DELETE, Suspect, REJECT

class CustomMessagePlugin(ScannerPlugin):
    def __init__(self, *args, **kwargs):
        ScannerPlugin.__init__(self, *args, **kwargs)
        self.allowed_recipients = ['test9@y.com']
        self.denied_recipients = ['test8@y.com','another@y.com']

    def examine(self, suspect):
        sender = suspect.from_address.lower()
        recipient = suspect.recipients[0].lower()

        if recipient in self.denied_recipients:
            # Send bounce message to the sender
            bounce_message = "Your email to {} has been rejected.".format(recipient)
            return REJECT, bounce_message
        else:
            return DUNNO

    def lint(self):
        return
    
    def __str__(self):
        return "Custom Plugin"

when mail sent from another@y.com doesnt get bounce mail when sent to itself ie another@y.com
How to go about? Any syntax issues? Where can i get help for bounce customization in fuglu

答案1

得分: 0

许多fuglu插件都有一个配置选项,用于自定义拒绝消息。

例如,如果您正在使用通用的action override plugin,您可以在可疑过滤器配置中配置拒绝消息:

from_domain example\.com REJECT  来自 example.com 的消息在这里不受欢迎

更具体的插件,如防病毒插件,也有拒绝消息配置,例如在clamav plugin中:

# 如果在预队列模式下运行并且 virusaction=REJECT,则使用拒绝消息模板
rejectmessage=threat detected: ${virusname}

如果您正在编写自己的自定义插件,您可以在examine() 函数的返回语句中作为第二个值简单传递拒绝消息:

def examine(self, suspect):
    ...
    return REJECT, "走开,我不想要这条消息"
英文:

Many fuglu plugins have a configuration option to customize the reject message.

For example, if you're using the generic action override plugin, you can configure the reject message in the suspect filter configuration :

from_domain example\.com REJECT  messages from example.com are not welcome here

More specific plugins like antivirus plugins have a reject message configuration as well, for example in the clamav plugin:

#reject message template if running in pre-queue mode and virusaction=REJECT
rejectmessage=threat detected: ${virusname}

If you're writing your own custom plugin, you can simply pass the reject message in your return statement in the examine() function as a second value:

def examine(self, suspect):
    ...
    return REJECT, "go away, I do not want this message"

答案2

得分: 0

成功使原始代码工作,通过在这里不返回 REJECT:

if deny_group_list:
    suspect.recipients = deny_group_list
    self._logger().info(
        '9999 ====== denied suspect.recipients: %s' %(suspect.recipients))
    self.send_bounce_message(suspect,deny_group_list,msubject)
    self._mark_bounce_sent(message_id, deny_group_list,msubject)

# 下面的部分已经被注释掉
# return REJECT

还从 examine 函数中移除了 最后的 return DUNNO,因为为所有情况指定了返回值。

英文:

Got the original code working, by not returning REJECT here:

if deny_group_list:
    suspect.recipients = deny_group_list
    self._logger().info(
        '9999 ====== denied suspect.recipients: %s' %(suspect.recipients))
    self.send_bounce_message(suspect,deny_group_list,msubject)
    self._mark_bounce_sent(message_id, deny_group_list,msubject)
  

      # below commented  
            #return REJECT

Also removed the last return DUNNO for the examine function as return value is specified for all conditions

huangapple
  • 本文由 发表于 2023年6月8日 14:51:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76429277.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定