How can I write a python plugin for an mail client Evolution

About programming and getting involved with Linux Mint development
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
kocmohabt228
Level 1
Level 1
Posts: 1
Joined: Wed Aug 02, 2023 5:11 am

How can I write a python plugin for an mail client Evolution

Post by kocmohabt228 »

I need to write a mail plugin Evolution 3.32.4-alt1 preferably in python. Plugin functionality: If the user sends an email not to the organization’s domain, then a dialog box with a warning about this and the “Cancel” and “Send” buttons should be displayed. How can this be implemented? How to make Evolution recognize the plugin?
Last edited by LockBot on Fri Feb 02, 2024 11:00 pm, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
spamegg
Level 14
Level 14
Posts: 5117
Joined: Mon Oct 28, 2019 2:34 am
Contact:

Re: How can I write a python plugin for an mail client Evolution

Post by spamegg »

Might be better suited for the Programming & Development subforum. viewforum.php?f=120
jacobmallll
Level 1
Level 1
Posts: 6
Joined: Thu Dec 14, 2023 5:07 am
Location: USA
Contact:

Re: How can I write a python plugin for an mail client Evolution

Post by jacobmallll »

As per knowledge, it's very simple-
Follow these steps-

1. Install Required Packages

Code: Select all

sudo apt-get install evolution-data-server-dev python3-gi
2. Write the Plugin Code:

Create a Python script for your plugin (https://packaging.python.org/en/latest/ ... g-plugins/).
Let's call it 'org_domain_warning.py':

Code: Select all

#!/usr/bin/env python3

from gi.repository import GObject
from gi.repository import Camel
from gi.repository import Evolution

class OrgDomainWarningPlugin(GObject.Object, Evolution.MailFilter):

    def filter(self, filter_str, message, user_data):
        # Extract recipient email addresses
        recipients = [addr.get_address() for addr in message.get_recipients()]

        # Check if any recipient is outside the organization's domain
        if any('your_organization_domain.com' not in recipient for recipient in recipients):
            # Display warning dialog
            dialog = Evolution.Dialog(
                'Warning',
                'You are sending an email outside the organization\'s domain. Are you sure you want to proceed?',
                Evolution.DialogFlags.MODAL | Evolution.DialogFlags.NO_SEPARATOR,
                Evolution.STOCK_DIALOG_WARNING,
                Evolution.Button('Cancel', Evolution.ResponseType.CANCEL),
                Evolution.Button('Send', Evolution.ResponseType.ACCEPT)
            )

            response = dialog.run()
            dialog.destroy()

            # If the response is 'Cancel', stop sending the email
            if response == Evolution.ResponseType.CANCEL:
                return Evolution.MailFilterResult.STOP

        # Continue sending the email
        return Evolution.MailFilterResult.CONTINUE

# Register the plugin
GObject.type_register(OrgDomainWarningPlugin)
Evolution.MailFilter.register_type(OrgDomainWarningPlugin)
3. Install the Plugin:

Code: Select all

sudo cp org_domain_warning.py /usr/lib/evolution/3.32/plugins/
4. Test the Plugin

I followed the same steps while I was create Plugin functions for this DevOps model.
Thanks
Jacob Mall
Locked

Return to “Programming & Development”