简体   繁体   中英

Incoming E-mail intercepted by PYTHON's ( sys.stdin.read(1024) ) is missing title and body content

I use /etc/aliases to redirect incoming emails
for the username "ooo" to a python script

( handled by SENDMAIL )

ooo:    "|/usr/bin/python /2/a.wsgi"

this is what a.wsgi looks like.

import os
import sys

a = sys.stdin.read(1024)
f = open('/2/email.txt','w')
f.write(a)

I sent a test e-mail to myself from my yahoo e-mail account but the whole title and body is missing.

on purpose i created a long title consisting of lot's of o's and a body consisting of lot's of o's with multiple lines so that i could see it.

when i look into the intercepted e-mail by python.. this is what email.txt file looks like.

[root@a 2]# cat email.txt
From a*****@ymail.com Thu Jul 25 09:41:49 2013
Received: from nm23-vm1.bullet.mail.bf1.yahoo.com (nm23-vm1.bullet.mail.bf1.yahoo.com [98.139.213.141])
    by domain.tld (8.14.4/8.14.4) with ESMTP id r6P9fm88005190
    for <ooo@*****.tld>; Thu, 25 Jul 2013 09:41:48 GMT
Received: from [98.139.215.142] by nm23.bullet.mail.bf1.yahoo.com with NNFMP; 25 Jul 2013 17:26:26 -0000
Received: from [98.139.212.228] by tm13.bullet.mail.bf1.yahoo.com with NNFMP; 25 Jul 2013 17:26:26 -0000
Received: from [127.0.0.1] by omp1037.mail.bf1.yahoo.com with NNFMP; 25 Jul 2013 17:26:26 -0000
X-Yahoo-Newman-Property: ymail-3
X-Yahoo-Newman-Id: 45121.53358.bm@omp1037.mail.bf1.yahoo.com
Received: (qmail 29958 invoked by uid 60001); 25 Jul 2013 17:26:26 -0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s1024; t=1374773185; bh=Nc9zHE1K2q237s4A2qN53+4bWmq6BswfttyIcwmUsF8=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=tN89b5lX46otPfK9builCXVNLty3jVx[root@a 2]# 

as you can see the subject is empty and body is not visible either.

otherwise i e-mailed myself

Subject: oooooooooooooooooooooooooooooooooooooooooo
Body : also lot's of o's but multiple lines so it'd be easy to see.

a = sys.stdin.read(1024)

reads no more than 1024 bytes. That is roughly the length of the email.txt you've posted. The discrepancy is probably due to redactions.

So, if you want the entire message, use

a = sys.stdin.read()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM