HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/postfix.cpython-310.pyc
o

�N�g�@�@s�dZddlZddlZddlZddlZddlZe�d�Ze�	e
�ZdZdZ
dd�Ze
fdd	�Ze
fd
d�Zdddd
ddde
fdd�Zdd�Zefdd�Zefdd�Zefdd�Zefdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�ZdS)'a�
Support for Postfix

This module is currently little more than a config file viewer and editor. It
is able to read the master.cf file (which is one style) and files in the style
of main.cf (which is a different style, that is used in multiple postfix
configuration files).

The design of this module is such that when files are edited, a minimum of
changes are made to them. Each file should look as if it has been edited by
hand; order, comments and whitespace are all preserved.
�Nz^\sz/etc/postfix/main.cfz/etc/postfix/master.cfcCstjj�d�r	dSdS)z6
    Only load the module if Postfix is installed
    ZpostfixT)Fz;postfix execution module not loaded: postfix not installed.)�salt�utils�path�which�rr�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/postfix.py�__virtual__src	
Cs�tjj�|d��}tjj�|���}Wd�n1swYg}i}|��D]M}|��r6|���	d�r<|�
|�q)|����}|d|d|d|d|d|d	|d
d�|dd��d
�}|d�d|d��}|�
|�|||<q)||fS)a
    Parse the master.cf file. This file is essentially a whitespace-delimited
    columnar file. The columns are: service, type, private (yes), unpriv (yes),
    chroot (yes), wakeup (never), maxproc (100), command + args.

    This function parses out the columns, leaving empty lines and comments
    intact. Where the value doesn't detract from the default, a dash (-) will
    be used.

    Returns a dict of the active config lines, and a list of the entire file,
    in order. These compliment each other.
    �rN�#r������� �)�service�	conn_type�private�unpriv�chroot�wakeup�maxproc�command)
rr�files�fopen�stringutils�
to_unicode�read�
splitlines�strip�
startswith�append�split�join)	r�fh_�	full_conf�	conf_list�	conf_dict�line�comps�	conf_line�dict_keyrrr�
_parse_master&s.
�
�


r.cC�t|�\}}|S)a�
    Return a dict of active config values. This does not include comments,
    spacing or order.

    The data returned from this function should not be used for direct
    modification of the main.cf file; other functions are available for that.

    CLI Examples:

    .. code-block:: bash

        salt <minion> postfix.show_master
        salt <minion> postfix.show_master path=/path/to/master.cf
    )r.)rr)r(rrr�show_masterP�r0�y�n�100�Tc
	Cs�t|	�\}
}g}|�d|��}
t||||||||�}|D])}t|t�r@|d|kr5|d|kr5|�|�q|�tdi|���q|�|�q|
|
vrO|�|�|rVt||	�d�|�S)a
    Set a single config value in the master.cf file. If the value does not
    already exist, it will be appended to the end.

    Because of shell parsing issues, '-' cannot be set as a value, as is normal
    in the master.cf file; either 'y', 'n' or a number should be used when
    calling this function from the command line. If the value used matches the
    default, it will internally be converted to a '-'. Calling this function
    from the Python API is not affected by this limitation

    The settings and their default values, in order, are: service (required),
    conn_type (required), private (y), unpriv (y), chroot (y), wakeup (n),
    maxproc (100), command (required).

    By default, this function will write out the changes to the master.cf file,
    and then returns the full contents of the file. By setting the
    ``write_conf`` option to ``False``, it will skip writing the file.

    CLI Example:

    .. code-block:: bash

        salt <minion> postfix.set_master smtp inet n y n n 100 smtpd
    rrr�
Nr)r.�_format_master�
isinstance�dictr#�_write_confr%)rrrrrrrrZ
write_confrr)r(�new_confr-Znew_liner*rrr�
set_mastercs0$�




r<c	
Cs`|dkrd}|dkrd}|dkrd}|dkrd}t|�}|dkr"d}d�||||||||�}|S)za
    Format the given values into the style of line normally used in the
    master.cf file.
    r2�-r3r4z,{:9s} {:5s} {:7s} {:7s} {:7s} {:7s} {:7s} {})�str�format)	rrrrrrrrr,rrrr7�s,�r7cCstjj�|d��}tjj�|���}Wd�n1swYg}|��D]6}|��s3|�	|�q't
�t|�rX|sA|�	|�q't
|dt�sLd|d<d�|d|g�|d<q'|�	|�q'i}|D]#}|��siqb|�d�roqb|�d�}d�|dd����||d	��<qb||fS)
a�
    Parse files in the style of main.cf. This is not just a "name = value" file;
    there are other rules:

    * Comments start with #
    * Any whitespace at the beginning of a line denotes that that line is a
        continuation from the previous line.
    * The whitespace rule applies to comments.
    * Keys defined in the file may be referred to as variables further down in
        the file.
    r	N���r5r6r
�=rr)rrrrrrrr r!r#�re�match�SWWSr8r>r%r"r$)rr&r'r(r*�pairsr+rrr�_parse_main�s2�



$rFcCr/)a
    Return a dict of active config values. This does not include comments,
    spacing or order. Bear in mind that order is functionally important in the
    main.cf file, since keys can be referred to as variables. This means that
    the data returned from this function should not be used for direct
    modification of the main.cf file; other functions are available for that.

    CLI Examples:

    .. code-block:: bash

        salt <minion> postfix.show_main
        salt <minion> postfix.show_main path=/path/to/main.cf
    )rF)rrEr(rrr�	show_mainr1rGcCs�t|�\}}g}t�dt�|��d��}||vr4|D]}t�||�r-|�|�d|���q|�|�qn|�|�d|���|}t||�|S)z�
    Set a single config value in the main.cf file. If the value does not already
    exist, it will be appended to the end.

    CLI Example:

    .. code-block:: bash

        salt <minion> postfix.set_main mailq_path /usr/bin/mailq
    �^z	([\s=]|$)z = )rFrB�compile�escaperCr#r:)�key�valuerrEr(r;Zkey_line_matchr*rrr�set_mains�
rMcCs~tjj�|d��-}|D]!}tjj�|�}t|t�r"|�d�	|��n|�|�|�d�qWd�dS1s8wYdS)z'
    Write out configuration file.
    �wrr6N)
rrrrrZto_strr8r9�writer%)Zconfrr&r*rrrr:5s

�"�r:c	Cs�d}td|���}g}t�d�}t�d�}d\}}}}}	|D]R}
t�d|
�r(qt�||
�rIt�||
�}|�d�}|�d�}|�d	�}|�d
�}qt�||
�r[t�||
�}|�d�}	q|
sqt|||||	f�rq|�|||||	d��q|S)
z{
    Show contents of the mail queue

    CLI Example:

    .. code-block:: bash

        salt '*' postfix.show_queue

    Zmailqzcmd.runzt(?P<queue_id>^[A-Z0-9]+)\s+(?P<size>\d+)\s(?P<timestamp>\w{3}\s\w{3}\s\d{1,2}\s\d{2}\:\d{2}\:\d{2})\s+(?P<sender>.+)z^\s+(?P<recipient>.+))NNNNNz^[-|postqueue:|Mail]�queue_id�size�	timestamp�sender�	recipient)rPrQrRrSrT)�__salt__r rBrIrC�group�allr#)�cmd�out�queueZ
queue_patternZrecipient_patternrPrQrRrSrTr*�mrrr�
show_queueCs@�



���	r\cC��ddd�}|st�d�|dks1t�}d}|D]
}|d|kr!|}q|s1d|��|d	<d
|d<|Sd|��}td
|�}|ddkrU|dkrLd|d	<|Sd�|�|d	<|S|dkr_d|d	<|Sd�||d�|d	<|S)z�
    Delete message(s) from the mail queue

    CLI Example:

    .. code-block:: bash

        salt '*' postfix.delete 5C33CA0DEA

        salt '*' postfix.delete ALL

    r5T��message�result�Require argument queue_id�ALLNrP�No message in queue with ID r_Fr`z
postsuper -d �cmd.run_all�retcoderz!Successfully removed all messagesz-Successfully removed message with queue id {}zUnable to removed all messagesz-Unable to remove message with queue id {}: {}�stderr��log�errorr\rUr?�rP�retrZZ_message�itemrXr`rrr�deleter�>

�
��
���rmcC��ddd�}|st�d�|dks1t�}d}|D]
}|d|kr!|}q|s1d|��|d	<d
|d<|Sd|��}td
|�}|ddkrU|dkrLd|d	<|Sd|��|d	<|S|dkr_d|d	<|Sd�||d�|d	<|S)z�
    Put message(s) on hold from the mail queue

    CLI Example:

    .. code-block:: bash

        salt '*' postfix.hold 5C33CA0DEA

        salt '*' postfix.hold ALL

    r5Tr^rarbNrPrcr_Fr`z
postsuper -h rdrerz(Successfully placed all messages on holdz2Successfully placed message on hold with queue id z$Unable to place all messages on holdz4Unable to place message on hold with queue id {}: {}rfrgrjrrr�hold��>

�
������rpcCro)z�
    Set held message(s) in the mail queue to unheld

    CLI Example:

    .. code-block:: bash

        salt '*' postfix.unhold 5C33CA0DEA

        salt '*' postfix.unhold ALL

    r5Tr^rarbNrPrcr_Fr`z
postsuper -H rdrerz&Successfully set all message as unheldz1Successfully set message as unheld with queue id z$Unable to set all message as unheld.z4Unable to set message as unheld with queue id {}: {}rfrgrjrrr�unhold�rqrrcCr])z�
    Requeue message(s) in the mail queue

    CLI Example:

    .. code-block:: bash

        salt '*' postfix.requeue 5C33CA0DEA

        salt '*' postfix.requeue ALL

    r5Tr^zRequired argument queue_idrbNrPrcr_Fr`z
postsuper -r rdrerz"Successfully requeued all messagesz.Successfully requeued message with queue id {}zUnable to requeue all messagesz.Unable to requeue message with queue id {}: {}rfrgrjrrr�requeuernrs)�__doc__�loggingrBZsalt.utils.filesrZsalt.utils.pathZsalt.utils.stringutilsrIrD�	getLogger�__name__rhZMAIN_CFZ	MASTER_CFrr.r0r<r7rFrGrMr:r\rmrprrrsrrrr�<module>s@


	*
�H*0/355