2013-02-02 32 views
5

मैं मार्कडाउन स्वरूपण का उपयोग करके text/plain संदेश बनाना चाहता हूं और उसे multipart/alternative संदेश में बदलना चाहता हूं जहां text/html भाग मार्कडाउन से उत्पन्न हुआ है। मैंने फ़िल्टर को कम करने के लिए फ़िल्टर कमांड का उपयोग करने का प्रयास किया है जो संदेश बनाता है, लेकिन ऐसा लगता है कि संदेश ठीक से नहीं भेजा जाता है। नीचे दिए गए कोड है (यह है कि अगर मैं सब पर multipart/alternative संदेशों करा सकते हैं सिर्फ परीक्षण कोड है।मल्टीपार्ट/वैकल्पिक मेल बनाने के लिए म्यूट में पाइथन का उपयोग

import sys 
from email.mime.text import MIMEText 
from email.mime.multipart import MIMEMultipart 

html = """<html> 
      <body> 
      This is <i>HTML</i> 
      </body> 
      </html> 
""" 

msgbody = sys.stdin.read() 

newmsg = MIMEMultipart("alternative") 

plain = MIMEText(msgbody, "plain") 
plain["Content-Disposition"] = "inline" 

html = MIMEText(html, "html") 
html["Content-Disposition"] = "inline" 

newmsg.attach(plain) 
newmsg.attach(html) 

print newmsg.as_string() 

दुर्भाग्य से, मठ में, आप केवल फिल्टर आदेश जब आप रचना के लिए भेजा संदेश के मुख्य भाग (हेडर मिल शामिल नहीं हैं)। मुझे लगता है कि यह काम करने के बाद, मुझे लगता है कि मार्कडाउन हिस्सा बहुत कठिन नहीं होगा।

उत्तर

1

अद्यतन: किसी ने पाइथन लिपि के साथ उपयोग करने के लिए म्यूट को कॉन्फ़िगर करने पर एक लेख लिखा था। मैंने कभी नहीं किया है यह hashcash and mutt, लेख muttrc की कॉन्फ़िगरेशन के माध्यम से जाता है और कोड उदाहरण देता है।


पुराना जवाब

यह आपकी समस्या का समाधान है?

#!/usr/bin/env python 

from email.mime.text import MIMEText 
from email.mime.multipart import MIMEMultipart 


# create the message 
msg = MIMEMultipart('alternative') 
msg['Subject'] = "My subject" 
msg['From'] = "[email protected]" 
msg['To'] = "[email protected]" 

# Text of the message 
html = """<html> 
      <body> 
      This is <i>HTML</i> 
      </body> 
      </html> 
""" 
text="This is HTML" 

# Create the two parts 
plain = MIMEText(text, 'plain') 
html = MIMEText(html, 'html') 

# Let's add them 
msg.attach(plain) 
msg.attach(html) 

print msg.as_string() 

हम प्रोग्राम को सहेजते हैं और परीक्षण करते हैं।

python test-email.py 

कौन देता है:

Content-Type: multipart/alternative; 
boundary="===============1440898741276032793==" 
MIME-Version: 1.0 
Subject: My subject 
From: [email protected] 
To: [email protected] 

--===============1440898741276032793== 
Content-Type: text/plain; charset="us-ascii" 
MIME-Version: 1.0 
Content-Transfer-Encoding: 7bit 

This is HTML 
--===============1440898741276032793== 
Content-Type: text/html; charset="us-ascii" 
MIME-Version: 1.0 
Content-Transfer-Encoding: 7bit 

<html> 
      <body> 
      This is <i>HTML</i> 
      </body> 
      </html> 

--===============1440898741276032793==-- 
+0

मैं इस कार्यक्रम को चलाने के लिए प्राप्त कर सकते हैं, लेकिन मुझे लगता है कि मेरी समस्या यह है कि मठ लिखें दौरान हेडर के साथ संदेश को छानने की अनुमति नहीं देता है। मुझे लगता है कि ऐसा करने के लिए म्यूट में बदलाव की आवश्यकता होगी। –

+0

इसलिए यह एक अजगर मुद्दा नहीं है। मैं उलझन में हूं। – karlcow

+0

मुझे लगता है कि प्रश्न होना चाहिए 'मैं इस स्क्रिप्ट को म्यूट में कैसे चला सकता हूं जैसे' मल्टीपार्ट/वैकल्पिक 'संदेश तैयार किया जाएगा'? –