intercept incoming and outgoing mail

Have a great idea for extending Zimbra? Share ideas, ask questions, contribute, and get feedback.
Post Reply
Vovan
Posts: 6
Joined: Thu Jan 16, 2020 11:56 am

intercept incoming and outgoing mail

Post by Vovan »

Hi!
How i can intercept incoming and outgoing mail header with a script to add mail events to my SQL table?
I would also like to have in the script an absolute link on the disk to the new letter.
Vovan
Posts: 6
Joined: Thu Jan 16, 2020 11:56 am

Re: intercept incoming and outgoing mail

Post by Vovan »

Hello everybody!
I used AdminWaitSetRequest (XML)

i try create WaitSet ... send to server

Code: Select all

<?xml version="1.0"?>
   <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:zimbra" xmlns:urn1="urn:zimbraAdmin">
    <env:Header><urn:context><urn:authToken>0_f4f8e9b791dddb79957c13fd0af7d4802d329599_69643d33363a66313637616333382d396630352d346131362d393764362d3635613830323534336666653b6578703d31333a313538303530363639323331383b61646d696e3d313a313b76763d313a303b747970653d363a7a696d6272613b753d313a613b7469643d31303a313938383439373531323b76657273696f6e3d31343a382e382e31355f47415f333836393b</urn:authToken></urn:context></env:Header>
     <env:Body>
        <urn1:AdminCreateWaitSetRequest allAccounts="true" defTypes="f"/>
    </env:Body>
   </env:Envelope>

Response from server

Code: Select all

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Header><context xmlns="urn:zimbra"><change token="4101"/></context></soap:Header><soap:Body><AdminCreateWaitSetResponse waitSet="AllWaitSet-6bfb704f-5f01-479d-b76c-c88d8429225c" defTypes="f" seq="0" xmlns="urn:zimbraAdmin"/></soap:Body></soap:Envelope>
Next send

Code: Select all

<?xml version="1.0"?>
   <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:zimbra" xmlns:urn1="urn:zimbraAdmin">
    <env:Header><urn:context><urn:authToken>0_f4f8e9b791dddb79957c13fd0af7d4802d329599_69643d33363a66313637616333382d396630352d346131362d393764362d3635613830323534336666653b6578703d31333a313538303530363639323331383b61646d696e3d313a313b76763d313a303b747970653d363a7a696d6272613b753d313a613b7469643d31303a313938383439373531323b76657273696f6e3d31343a382e382e31355f47415f333836393b</urn:authToken></urn:context></env:Header>
     <env:Body>
        <urn1:AdminWaitSetRequest waitSet="AllWaitSet-b61d12ba-e34d-4269-ba7d-f2998cd76c93" seq="0" defTypes="f" block="1" expand="true"/>
    </env:Body>
   </env:Envelope>

Response from server after incoming any new mail.

Code: Select all

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Header><context xmlns="urn:zimbra"><change token="4101"/></context></soap:Header><soap:Body><AdminWaitSetResponse waitSet="AllWaitSet-b61d12ba-e34d-4269-ba7d-f2998cd76c93" seq="2-1580463504781-1579249499-20429" xmlns="urn:zimbraAdmin"><a id="6914a890-53ce-497b-a3f8-85e93ffd59d5" changeid="4532"/></AdminWaitSetResponse></soap:Body></soap:Envelope>
Now. How do I display a folder that has changed? And what has changed there? There is no useful information in the answer.
What else needs to be done to get all the data about the event?
gumkins
Posts: 2
Joined: Thu Jul 27, 2017 8:21 am

Re: intercept incoming and outgoing mail

Post by gumkins »

Hello,

I'm currently trying to use AdminWaitSetRequest and have faced with the same question.

Have you found the answer?
User avatar
barrydegraaff
Zimbra Employee
Zimbra Employee
Posts: 242
Joined: Tue Jun 17, 2014 3:31 am
Contact:

Re: intercept incoming and outgoing mail

Post by barrydegraaff »

This can be done using a milter filter,

https://github.com/Zimbra-Community/mai ... ter/milter

Then you can modify `zimbra_mailinglists_milter.py` and instead of having it add/remove/replace headers in the mail, you can put them in a database.

Perhaps what you are looking for is already in Zimbra's MariaDB? But that is not clear to me at this point.
--
Barry de Graaff
Email: barry.degraaff [at] synacor [dot] com
Admin of Zimbra-Community Github: https://github.com/orgs/Zimbra-Community/ and the
Zimlet Gallery https://gallery.zetalliance.org/extend/
yasin2020
Posts: 1
Joined: Tue Aug 11, 2020 4:08 pm

Re: intercept incoming and outgoing mail

Post by yasin2020 »

Hello,

I'm currently trying to use AdminWaitSetRequest and have faced with the same question.

Have you found the answer?
Vovan
Posts: 6
Joined: Thu Jan 16, 2020 11:56 am

Re: intercept incoming and outgoing mail

Post by Vovan »

I found a way to intercept emails through python. (https://github.com/Zimbra-Community/python-zimbra)

Code: Select all

info_request.add_request(
    'WaitSetRequest',
    {
           'waitSet': waitset,
           'seq': seq,
           'block': '1',
           'defTypes': defTypes,
           'timeout': "1000000",
           'expand': '1',
           'update': {
                       'a': {
                       'name': 'admin@blablabla',
                       'token': '401',
                       'types': defTypes
                       ,
      },

    },
    'urn:zimbraMail'
)
info_response = comm.send_request(info_request)
if not info_response.is_fault():
    print (info_response.get_response()['WaitSetResponse'])

getting

[root@mail zmadmin]# python test.py
{u'a': {u'id': u'7ac0ebb7-2bd5-4c48-828c-74cbc0e636d1', u'changeid': 7855}, u'waitSet': u'WaitSet-2c99cd74-b90f-4948-9e11-c29ff6c5f884', u'seq': u'9'}
[root@mail zmadmin]#


Now I need these messages to come in a loop when a new letter is received
[root@mail zmadmin]# python test.py
{u'a': {u'id': u'7ac0ebb7-2bd5-4c48-828c-74cbc0e636d1', u'changeid': 7855}, u'waitSet': u'WaitSet-2c99cd74-b90f-4948-9e11-c29ff6c5f884', u'seq': u'9'}
{u'a': {u'id': u'7ac0ebb7-2bd5-4c48-828c-74cbc0e636d1', u'changeid': 7858}, u'waitSet': u'WaitSet-2c99cd74-b90f-4948-9e11-c29ff6c5f884', u'seq': u'10'}
{u'a': {u'id': u'7ac0ebb7-2bd5-4c48-828c-74cbc0e636d1', u'changeid': 7860}, u'waitSet': u'WaitSet-2c99cd74-b90f-4948-9e11-c29ff6c5f884', u'seq': u'11'}
{u'a': {u'id': u'7ac0ebb7-2bd5-4c48-828c-74cbc0e636d1', u'changeid': 7862}, u'waitSet': u'WaitSet-2c99cd74-b90f-4948-9e11-c29ff6c5f884', u'seq': u'12'}
{u'a': {u'id': u'7ac0ebb7-2bd5-4c48-828c-74cbc0e636d1', u'changeid': 7864}, u'waitSet': u'WaitSet-2c99cd74-b90f-4948-9e11-c29ff6c5f884', u'seq': u'13'}

can someone help me run this as a service?
Post Reply