Django text message mailbox - maximum line length (and how to change it)?

# settings.py EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend' # view.py from django.core.mail import send_mail def send_letter(request): the_text = 'this is a test of a really long line that has more words that could possibly fit in a single column of text.' send_mail('some_subject', the_text, ' me@test.com ', [' me@test.com ']) 

The Django view code above leads to a text file that contains a broken line:

 this is a test of a really long line that has more words that could possibl= y fit in a single column of text. ------------------------------------------------------------------------------- 

Does anyone know how to change it so that the output file does not have lines? Are there any settings in Django that control this? Version 1.2 of Django.

Update - to backup the level and explain my original problem :) I am using the django registration application, which sends an email with an account activation link. This link is a long URL with a random token at the end (30+ characters), and as a result, the line breaks in the middle of the marker.

In case the problem is with the Django email file mailbox, I switched to the smtp server and started the built-in smtpd Python server in debug mode. This threw my email to the console where it was still broken.

I am sure that the work of django registration works, and millions of people use it from users. So this should be what I did wrong or incorrectly configured. I just don't understand that.

Update 2 - according to the message on the Django list, this is really the basic Python email.MIMEText object , which, if correctly, only pushes the problem back a bit more. He still doesn't tell me how to fix it. Looking at the documents, I do not see anything that even mentions the wrapper.

Update 3 (sigh) - I ruled out that this is a problem with the MIMEText object. I used a clean Python program and smtplib / MIMEText to create and send a test email, and it worked fine. He also used charset = "us-ascii", which, according to someone, was the only encoding that does not wrap text in MIMEText objects. I donโ€™t know if this is correct or not, but I looked more closely at my Django email output and it has the utf-8 encoding.

Can the wrong encoding be a problem? And if so, how do I change it in Django?

Here's the whole output from Django's email:

 ---------- MESSAGE FOLLOWS ---------- Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: some_subject From: me@test.com To: me@test.com Date: Tue, 17 May 2011 19:58:16 -0000 this is a test of a really long line that has more words that could possibl= y fit in a single column of text. ------------ END MESSAGE ------------ 
+6
source share
4 answers

You may be able to get your email client to not break the 78-digit soft limit by creating an EmailMessage object and passing it to headers = {'format': 'flowed'} Also:

 from django.core.mail import EmailMessage def send_letter(request): the_text = 'this is a test of a really long line that has more words that could possibly fit in a single column of text.' email = EmailMessage( subject='some_subject', body=the_text, from_email=' me@test.com ', to=[' me@test.com '], headers={'format': 'flowed'}) email.send() 

If this does not work, try using the non-debug smtp setup to send the file to the actual email client, which displays the email according to the rules defined in the email header.

+4
source

I saw that it is python2.5 and it is fixed in python2.7.

The corresponding code in email / generator.py now contains a comment

 # Header got lots of smarts, so use it. Note that this is # fundamentally broken though because we lose idempotency when # the header string is continued with tabs. It will now be # continued with spaces. This was reversedly broken before we # fixed bug 1974. Either way, we lose. 

You can read about the error here http://bugs.python.org/issue1974

Or you can just change '\ t' to '' in this line email / generator.py

 print >> self._fp, Header( v, maxlinelen=self._maxheaderlen, header_name=h, continuation_ws='\t').encode() 
+1
source

Try defining EMAIL_BACKEND in settings.py . Maybe this does not solve your problem, but it is the right place to determine it, otherwise it will most likely not be used.

(Since I'm not sure that I will solve your problem here, I tried to comment on yours, but apparently I can not.)

0
source

Email lines are not โ€œbrokenโ€ as such - they are simply quoted-printable encoded. Thus, 76 characters are entered =\n . Any competent email client must correctly decode the message and remove the gap.

If you want to represent the body of the message with decryption, you can use it by passing decode=True to the get_payload method

 body = email.get_payload(decode=True) 

This says the message decodes the encoding with quotes.

Moreover, if your main problem is to get the python console debug server to print the decoded message, you can do something quick and dirty, like this snippet instead of using the built-in DebuggingServer . More correctly, you can parse the string โ€œdataโ€ as an email object, print the headers you care about, then print the body using decode=True .

0
source

Source: https://habr.com/ru/post/887076/


All Articles