Repository: ietf-tools/datatracker

Issue:
Handle long email header fields in Message
### Describe the issue

Several of the header fields on the `Message` class, intended to represent an email message, are implemented as `CharField(max_length=1024)`. That has, at least once, been too short for the `To` field on a legitimate email, causing a failure.

These should be `TextField` fields - better to leave deciding the longest reasonable length to the code generating the message.

### Code of Conduct

- [X] I agree to follow the [IETF's Code of Conduct](https://github.com/ietf-tools/.github/blob/main/CODE_OF_CONDUCT.md)


Discussion:

Resolving patch:
diff --git a/ietf/message/migrations/0001_initial.py b/ietf/message/migrations/0001_initial.py
--- a/ietf/message/migrations/0001_initial.py
+++ b/ietf/message/migrations/0001_initial.py
@@ -1,9 +1,10 @@
-# Generated by Django 2.2.28 on 2023-03-20 19:22
+# Generated by Django 2.2.28 on 2023-03-30 19:14
 
 from django.db import migrations, models
 import django.db.models.deletion
 import django.utils.timezone
 import email.utils
+import ietf.message.models
 import ietf.utils.models
 
 
@@ -24,15 +25,15 @@ class Migration(migrations.Migration):
             fields=[
                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                 ('time', models.DateTimeField(default=django.utils.timezone.now)),
-                ('subject', models.CharField(max_length=255)),
-                ('frm', models.CharField(max_length=255)),
-                ('to', models.CharField(max_length=1024)),
-                ('cc', models.CharField(blank=True, max_length=1024)),
-                ('bcc', models.CharField(blank=True, max_length=255)),
-                ('reply_to', models.CharField(blank=True, max_length=255)),
+                ('subject', ietf.message.models.HeaderField()),
+                ('frm', ietf.message.models.HeaderField()),
+                ('to', ietf.message.models.HeaderField()),
+                ('cc', ietf.message.models.HeaderField(blank=True)),
+                ('bcc', ietf.message.models.HeaderField(blank=True)),
+                ('reply_to', ietf.message.models.HeaderField(blank=True)),
                 ('body', models.TextField()),
                 ('content_type', models.CharField(blank=True, default='text/plain', max_length=255)),
-                ('msgid', models.CharField(blank=True, default=email.utils.make_msgid, max_length=255, null=True)),
+                ('msgid', ietf.message.models.HeaderField(blank=True, default=email.utils.make_msgid, null=True)),
                 ('sent', models.DateTimeField(blank=True, null=True)),
                 ('by', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='person.Person')),
                 ('related_docs', models.ManyToManyField(blank=True, to='doc.Document')),
diff --git a/ietf/message/models.py b/ietf/message/models.py
--- a/ietf/message/models.py
+++ b/ietf/message/models.py
@@ -4,6 +4,7 @@
 
 import email.utils
 
+from django.forms import TextInput
 from django.db import models
 from django.utils import timezone
 
@@ -16,19 +17,26 @@
 from ietf.utils.models import ForeignKey
 from ietf.utils.mail import get_email_addresses_from_text
 
+
+class HeaderField(models.TextField):
+    """TextField that defaults to a TextInput widget"""
+    def formfield(self, **kwargs):
+        return super().formfield(**{'widget': TextInput, **kwargs})
+
+
 class Message(models.Model):
     time = models.DateTimeField(default=timezone.now)
     by = ForeignKey(Person)
 
-    subject = models.CharField(max_length=255)
-    frm = models.CharField(max_length=255)
-    to = models.CharField(max_length=1024)
-    cc = models.CharField(max_length=1024, blank=True)
-    bcc = models.CharField(max_length=255, blank=True)
-    reply_to = models.CharField(max_length=255, blank=True)
+    subject = HeaderField()
+    frm = HeaderField()
+    to = HeaderField()
+    cc = HeaderField(blank=True)
+    bcc = HeaderField(blank=True)
+    reply_to = HeaderField(blank=True)
     body = models.TextField()
     content_type = models.CharField(default="text/plain", max_length=255, blank=True)
-    msgid = models.CharField(max_length=255, blank=True, null=True, default=email.utils.make_msgid)
+    msgid = HeaderField(blank=True, null=True, default=email.utils.make_msgid)
 
     related_groups = models.ManyToManyField(Group, blank=True)
     related_docs = models.ManyToManyField(Document, blank=True)


Test patch: