← back to Qwen38 Viewer

__pycache__/mail-bridge.cpython-314.pyc

82 lines

+
���j9��L�Rt^RIt^RIt^RIt^RIt^RIt^RIt^RIt^RIt^RI	t	^RI
t
^RIt^RIH
t
^RIHtHtHt^RIHtRtRtRtRt]P2P5R	R
4t]P2P5RR4tRUu0uFqP;4kK	upt^t^(t R
t!Rt"]
PFPI4R,t%]
PFPI4R,t&Rt'Rt(Rt)Rt*Rt+Rt,Rt-Rt.Rt/Rt0Rt1]2R8Xd
]1!4R#R#uupi)u�
qwen mail bridge — lets ALLOWLISTED senders email qwen@agentabrams.com and get
an inline reply from the local uncensored qwen3.8-27b-heretic (Ollama).

ARMED per Steve's explicit authorization (2026-08-19).

Hard safety controls (this fronts an UNCENSORED model + sends outbound mail):
  * ALLOWLIST-ONLY: replies exclusively to the 4 addresses below. Any other
    sender -> marked read, logged, NEVER answered (not an open relay).
  * LOOP GUARD: never replies to itself, mailer-daemon, no-reply, or any message
    carrying Auto-Submitted / Precedence:bulk / List-* headers.
  * RATE CAP: at most MAX_PER_RUN replies per poll, MAX_PER_SENDER_DAY per sender.
  * Body + token caps.
Runs once per invocation (launchd StartInterval). Idempotent via IMAP \Seen.
N)�EmailMessage)�	parseaddr�
formataddr�
make_msgid)�requestzqwen@agentabrams.comzimap.purelymail.comzsmtp.purelymail.comiK�
OLLAMA_URLzhttp://127.0.0.1:11434�MODELzqwen3.8-27b-hereticipi�z.qwen-mail-bridge-state.jsonz.qwen-mail-bridge.logc�J�\PP4PRR7RV2p\V4\PR4;_uu_4q"P
VR,4RRR4R# +'giR#;i \dR#i;i)�seconds)�timespec� �a�
N)�datetime�now�	isoformat�print�LOG�open�write�OSError)�m�line�fs&  �mail-bridge.py�logr+sm�����#�#�%�/�/��/�C�
D�A�a�S�I�D�	�$�K��
�X�X�c�]�]�a������!5�]�]�]�]����D��s0�B�A?�5B�?B	�
B�B�B"�!B"c��\PPR4pV'dV#\PP4R,pVP
4P4FapVPR4'gKVPR^4^,P4PR4PR4u#	\R4h)�QWEN_MAIL_PASSzProjects/secrets-manager/.envzQWEN_MAIL_PASS=�=�"�'zQWEN_MAIL_PASS not found)�os�environ�get�pathlib�Path�home�	read_text�
splitlines�
startswith�split�strip�
SystemExit)�p�envf�lns   r�get_pwr02s���
�
�
���'�(�A���(��<�<����!@�@�D��n�n��)�)�+��
�=�=�*�+�+��8�8�C��#�A�&�,�,�.�4�4�S�9�?�?��D�D�,��/�
0�0�c�x�\P!\P44# \d/u#i;i�N)�json�loads�STATEr'�	Exception�r1r�
load_stater9<s'���
�
�5�?�?�,�-�	-����R�i��s�')�
9�9c�|�\P\P!V44R# \dR#i;ir3)r6�
write_textr4�dumpsr)�ss&r�
save_stater>?s%��	�	�	�$�*�*�Q�-�	(����D��s�),�;�;c�&�VPR4;'gRP4R9dR#VPR4;'gRP4R9dR#VPR4'gVPR4'dR#R#)	�Auto-Submitted�T�
PrecedencezList-IdzList-UnsubscribeF)rA�no)�bulk�list�junk)r#�lower)�msgs&r�is_bulkrICsp����� �!�'�'�R�.�.�0�
�B�4������#�#��*�*�,�0H�H�QU�
�w�w�y���S�W�W�%7�8�8��r1c��VP4# \d4TPRR7pT'dTPRR4u#Ru#i;i)T)�decodezutf-8�ignorerA)�get_contentr7�get_payloadrK)�part�pls& r�_decoderQIsK��� � �"�	"���:�
�
�
�T�
�
*��/1�r�y�y��(�+�9�r�9�:�s��$A�A�
A�Ac	���\P!RRV4p\P!RRV4p\P!RR\P!RRV44P4#)z(?is)<(script|style).*?</\1>rz(?s)<[^>]+>z[ \t]*\nrz[ \t]+)�re�subr+)�hs&r�_strip_htmlrVOsP��
���.��Q�7�A�
���~�s�A�&�A�
�6�6�+�t�R�V�V�I�s�A�%>�?�E�E�G�Gr1c���RRr!VP4'd�VP4FnpVP4pR\VP	R449dK4VR8XdV'g\V4pKPVR8XgKYV'dKc\V4pKp	M,VP4R8Xd
\V4pM\V4pVP
4;'g\V4#)rA�
attachmentzContent-Dispositionz
text/plainz	text/html)�is_multipart�walk�get_content_type�strr#rQr+rV)rH�text�htmlrO�cts&    r�
plain_bodyr`Ts����R�$�
������H�H�J�D��&�&�(�B��s�4�8�8�,A�#B�C�C�X��\�!�$�w�t�}���{�"�4�4���
��	����!�[�0����$��S�\�d��:�:�<�,�,�;�t�,�,r1c�j�.pVP4FpVP4PR4'dK*\P!RVP44'dM,VP4R9dMVPV4K�	RP
V4P4#)�>z^On .* wrote:$r)z--z-- )r(r+r)rS�match�append�join)�body�outr/s&  r�strip_quotesrhas��
�C��o�o���
�8�8�:� � ��%�%�x�
�8�8�%�r�x�x�z�2�2�E�
�8�8�:��&���
�
�2��	 �
�9�9�S�>���!�!r1c�(�\P!R\RRRRV/.RRRRR	R
RR\//4P	4p\
P!\R
2VRR/R7p\
P!VRR7;_uu_4p\P!VP4P44pRRR4XPR/4;'g/PRR4P4;'gR# +'giLT;i)�model�messages�role�user�content�streamF�
keep_alive�30m�options�temperatureg�������?�num_predictz	/api/chatzContent-Typezapplication/json)�data�headersi,��timeoutN�messagerAz
(no response))r4r<r�NUM_PREDICT�encode�urlreq�Request�OLLAMA�urlopenr5�readrKr#r+)�promptru�req�r�js&    r�ask_qwenr�js����:�:�w��z�V�V�Y�PV�4W�3X����e� �=�#�}�k�"R�T�U�U[�U[�U]�	��.�.�F�8�9�-�D�>�Se�Bf�
g�C�	����S�	)�	)�Q��J�J�q�v�v�x���(�)��
*�
�E�E�)�R� �&�&�B�+�+�I�r�:�@�@�B�U�U�o�U�
*�	)�s�3D�D	c� �\4p\4p\PP	4P4pVP
V/4p^p\P!4p\P!\RVR7pVP\V4VPR4VPRR4wrxV'd'V^,'dV^,P!4M.p	\#R\%V	4R24Rp
V	EF�pV\&8�d\#R4EM�VP)VR	4wr|\*P,!V^,^,4p
\/V
P
R
R44^,P14p\2P4!RR
V4pV
P
RR4pV\8XgRV9gVP7R24'd$\#RV24VP9VRR4K�\;V
4'd%\#RV24VP9VRR4EK0V\<9d)\#RVRV:24VP9VRR4EKcVP
V^4\>8�d%\#RV24VP9VRR4EK�\A\CV
44R\DPG4pV'g%\#RV24VP9VRR4EK�\#RVRV:R\%V424\IV4p\M4p\OR\34TR
&TTR&TP14P7R4'dTMRT2TR&T
P
R 4pT'd7TTR!&T
P
R"R4R#,T,PG4TR"&\QR$R%7TR &R&TR'&TPSTR(,4T
fJ\TPV!\X\Z^<R)7p
T
P]TR*7T
P\T4T
P_T4TP9TRR4TP
T^4^,Y>&T^,
p\#R+TR,\%T4R-24EK�	V
eV
Pa4VPc4W#/p\eV4\#R0VR124R# \Jdp\#RT24Rp?EKRp?ii;i \JdUp\#R.TR/T24TP9TRR4T
Pa4M \JdMi;iRp
Rp?EKiRp?ii;i \JdL�i;i)3�i�)�ssl_context�INBOXN�UNSEENzpoll: z unseenzrate: MAX_PER_RUN hit, stoppingz(RFC822)�FromrAz\+[^@]*@�@�Subjectz(no subject)z
mailer-daemonzskip loop-guard from=z+FLAGSz\Seenzskip bulk/auto from=zIGNORE non-allowlisted from=z subj=zskip per-sender cap from=zskip empty body from=zANSWER from=z chars=zqwen error: zQwen3.8 Heretic�Tozre:zRe: z
Message-IDzIn-Reply-To�
Referencesrzagentabrams.com)�domainzauto-repliedr@uA

— qwen3.8-27b-heretic (local, uncensored) via agentabrams.comrw)�contextzreplied to z (z chars)zsmtp error to z: zdone: z replied)zno-reply�noreply)3r0r9r�date�todayrr#�ssl�create_default_context�imaplib�	IMAP4_SSL�	IMAP_HOST�login�MAILBOX�select�searchr*r�len�MAX_PER_RUN�fetch�email�message_from_bytesrrGrSrTr)�storerI�	ALLOWLIST�MAX_PER_SENDER_DAYrhr`�MAX_BODY_CHARSr+r�r7rrr�set_content�smtplib�SMTP�	SMTP_HOST�	SMTP_PORT�starttls�send_message�quit�logoutr>)�pw�stater��counts�replied�ctx�M�typru�ids�smtp�num�mdrH�frm�base�subjrf�answer�e�reply�mids                      r�mainr�ss���	��B��L�E��M�M���!�+�+�-�E�
�Y�Y�u�b�
!�F��G�

�
$�
$�
&�C����)�S�c�:�A��G�G�G�R���H�H�W������x�(�I�C�!�d�1�g�g�$�q�'�-�-�/�2�C��&��S��
�'�"�#��D����k�!��1�2�E��'�'�#�z�*����&�&�r�!�u�Q�x�0��������+�,�Q�/�5�5�7���v�v�k�3��,���w�w�y�.�1���7�?�o��4����G^�8_�8_��'��u�-�.�����X�x�0P�RZ��3�<�<��&�s�e�,�-�q�w�w�s�H�h�/O�QY��i���.�s�e�6�$��B�C�Q�W�W�S�RZ�\d�Ee�go��:�:�c�1��!3�3��+�C�5�1�2�A�G�G�C��8�4T�V^��J�s�O�,�_�n�=�C�C�E����'��u�-�.�����X�x�0P�RZ��l�3�%�v�d�X�W�S��Y�K�@�A�	.��d�^�F����"�$5�w�#?�@��f�
���d��#'�:�:�<�#:�#:�5�#A�#A�4��d�V�}��i���g�g�l�#���#&�E�-� �$'�G�G�L�"�$=��$C�c�$I�"Q�"Q�"S�E�,��(�0A�B��l��"0����
���&�#h�h�i�	��|��|�|�I�y�"�E���
�
�c�
�*�D�J�J�w��,C����e�$�
�G�G�C��8�,� �*�*�S�!�,�q�0�F�K��q�L�G��+�c�U�"�S��[�M��9�:�c�r��
�Y�Y�[��H�H�J�
�O�E��u���&��	��"�#��K�	.��,�q�c�"�#�X��	.��0�	��.���R��s�+�,�
�G�G�C��8�,�������"�d�"���D��	����$��sg�$S5�=B0T�6U?�5T�T�T�U<�($U7�U�U7�U+�(U7�*U+�+U7�7U<�?V
�V
�__main__)zinfo@designerwallcoverings.comzsteve@designerwallcoverings.comzbrowntwn@gmail.comztheagentabrams@gmail.com)3�__doc__r!�sysr4r��timer�r�r�rSr$r�
email.messager�email.utilsrrr�urllibrr|r�r�r�r�r"r#r~rrGr�r�r�r�rzr%r&r6rrr0r9r>rIrQrVr`rhr�r��__name__)r
s0r�<module>r�s)���P�O�O�O�O�O�&�9�9�$�"��!�	�!�	��	��J�J�N�N�<�)A�B���J�J�N�N�7�$9�:��!�
�!�1�W�W�Y�!�
�	���������������<�<��������5�5���1� ���:�H�
-�"�V�O$�b�z���F���O
s�	D!