We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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)

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ietf/message/migrations/0001_initial.py`
Content:
```
1 # Generated by Django 2.2.28 on 2023-03-20 19:22
2 
3 from django.db import migrations, models
4 import django.db.models.deletion
5 import django.utils.timezone
6 import email.utils
7 import ietf.utils.models
8 
9 
10 class Migration(migrations.Migration):
11 
12     initial = True
13 
14     dependencies = [
15         ('group', '0001_initial'),
16         ('person', '0001_initial'),
17         ('name', '0001_initial'),
18         ('doc', '0001_initial'),
19     ]
20 
21     operations = [
22         migrations.CreateModel(
23             name='Message',
24             fields=[
25                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
26                 ('time', models.DateTimeField(default=django.utils.timezone.now)),
27                 ('subject', models.CharField(max_length=255)),
28                 ('frm', models.CharField(max_length=255)),
29                 ('to', models.CharField(max_length=1024)),
30                 ('cc', models.CharField(blank=True, max_length=1024)),
31                 ('bcc', models.CharField(blank=True, max_length=255)),
32                 ('reply_to', models.CharField(blank=True, max_length=255)),
33                 ('body', models.TextField()),
34                 ('content_type', models.CharField(blank=True, default='text/plain', max_length=255)),
35                 ('msgid', models.CharField(blank=True, default=email.utils.make_msgid, max_length=255, null=True)),
36                 ('sent', models.DateTimeField(blank=True, null=True)),
37                 ('by', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='person.Person')),
38                 ('related_docs', models.ManyToManyField(blank=True, to='doc.Document')),
39                 ('related_groups', models.ManyToManyField(blank=True, to='group.Group')),
40             ],
41             options={
42                 'ordering': ['time'],
43             },
44         ),
45         migrations.CreateModel(
46             name='SendQueue',
47             fields=[
48                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
49                 ('time', models.DateTimeField(default=django.utils.timezone.now)),
50                 ('send_at', models.DateTimeField(blank=True, null=True)),
51                 ('sent_at', models.DateTimeField(blank=True, null=True)),
52                 ('note', models.TextField(blank=True)),
53                 ('by', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='person.Person')),
54                 ('message', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='message.Message')),
55             ],
56             options={
57                 'ordering': ['time'],
58             },
59         ),
60         migrations.CreateModel(
61             name='MessageAttachment',
62             fields=[
63                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
64                 ('filename', models.CharField(blank=True, db_index=True, max_length=255)),
65                 ('content_type', models.CharField(blank=True, max_length=255)),
66                 ('encoding', models.CharField(blank=True, max_length=255)),
67                 ('removed', models.BooleanField(default=False)),
68                 ('body', models.TextField()),
69                 ('message', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='message.Message')),
70             ],
71         ),
72         migrations.CreateModel(
73             name='AnnouncementFrom',
74             fields=[
75                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
76                 ('address', models.CharField(max_length=255)),
77                 ('group', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='group.Group')),
78                 ('name', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='name.RoleName')),
79             ],
80             options={
81                 'verbose_name_plural': 'Announcement From addresses',
82             },
83         ),
84         migrations.AddIndex(
85             model_name='sendqueue',
86             index=models.Index(fields=['time'], name='message_sen_time_07ab31_idx'),
87         ),
88         migrations.AddIndex(
89             model_name='message',
90             index=models.Index(fields=['time'], name='message_mes_time_20eabf_idx'),
91         ),
92     ]
93
```

Path: `ietf/message/models.py`
Content:
```
1 # Copyright The IETF Trust 2012-2020, All Rights Reserved
2 # -*- coding: utf-8 -*-
3 
4 
5 import email.utils
6 
7 from django.db import models
8 from django.utils import timezone
9 
10 import debug                            # pyflakes:ignore
11 
12 from ietf.person.models import Person
13 from ietf.group.models import Group
14 from ietf.doc.models import Document
15 from ietf.name.models import RoleName
16 from ietf.utils.models import ForeignKey
17 from ietf.utils.mail import get_email_addresses_from_text
18 
19 class Message(models.Model):
20     time = models.DateTimeField(default=timezone.now)
21     by = ForeignKey(Person)
22 
23     subject = models.CharField(max_length=255)
24     frm = models.CharField(max_length=255)
25     to = models.CharField(max_length=1024)
26     cc = models.CharField(max_length=1024, blank=True)
27     bcc = models.CharField(max_length=255, blank=True)
28     reply_to = models.CharField(max_length=255, blank=True)
29     body = models.TextField()
30     content_type = models.CharField(default="text/plain", max_length=255, blank=True)
31     msgid = models.CharField(max_length=255, blank=True, null=True, default=email.utils.make_msgid)
32 
33     related_groups = models.ManyToManyField(Group, blank=True)
34     related_docs = models.ManyToManyField(Document, blank=True)
35 
36     sent = models.DateTimeField(blank=True, null=True)
37 
38     class Meta:
39         ordering = ['time']
40         indexes = [
41             models.Index(fields=['time',]),
42         ]
43 
44     def __str__(self):
45         return "'%s' %s -> %s" % (self.subject, self.frm, self.to)
46 
47     def get(self, field):
48         r = getattr(self, field)
49         return r if isinstance(r, list) else get_email_addresses_from_text(r)
50             
51 
52 class MessageAttachment(models.Model):
53     message = ForeignKey(Message)
54     filename = models.CharField(max_length=255, db_index=True, blank=True)
55     content_type = models.CharField(max_length=255, blank=True)
56     encoding = models.CharField(max_length=255, blank=True)
57     removed = models.BooleanField(default=False)
58     body = models.TextField()
59 
60     def __str__(self):
61         return self.filename
62 
63 
64 class SendQueue(models.Model):
65     time = models.DateTimeField(default=timezone.now)
66     by = ForeignKey(Person)
67     
68     message = ForeignKey(Message)
69     
70     send_at = models.DateTimeField(blank=True, null=True)
71     sent_at = models.DateTimeField(blank=True, null=True)
72 
73     note = models.TextField(blank=True)
74     
75     class Meta:
76         ordering = ['time']
77         indexes = [
78             models.Index(fields=['time',]),
79         ]
80 
81     def __str__(self):
82         return "'%s' %s -> %s (sent at %s)" % (self.message.subject, self.message.frm, self.message.to, self.sent_at or "<not yet>")
83 
84 
85 class AnnouncementFrom(models.Model):
86     name = ForeignKey(RoleName)
87     group = ForeignKey(Group)
88     address = models.CharField(max_length=255)
89 
90     def __str__(self):
91         return self.address
92 
93     class Meta:
94         verbose_name_plural='Announcement From addresses'
95         
96
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
             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)

{"golden_diff": "diff --git a/ietf/message/migrations/0001_initial.py b/ietf/message/migrations/0001_initial.py\n--- a/ietf/message/migrations/0001_initial.py\n+++ b/ietf/message/migrations/0001_initial.py\n@@ -1,9 +1,10 @@\n-# Generated by Django 2.2.28 on 2023-03-20 19:22\n+# Generated by Django 2.2.28 on 2023-03-30 19:14\n \n from django.db import migrations, models\n import django.db.models.deletion\n import django.utils.timezone\n import email.utils\n+import ietf.message.models\n import ietf.utils.models\n \n \n@@ -24,15 +25,15 @@\n             fields=[\n                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),\n                 ('time', models.DateTimeField(default=django.utils.timezone.now)),\n-                ('subject', models.CharField(max_length=255)),\n-                ('frm', models.CharField(max_length=255)),\n-                ('to', models.CharField(max_length=1024)),\n-                ('cc', models.CharField(blank=True, max_length=1024)),\n-                ('bcc', models.CharField(blank=True, max_length=255)),\n-                ('reply_to', models.CharField(blank=True, max_length=255)),\n+                ('subject', ietf.message.models.HeaderField()),\n+                ('frm', ietf.message.models.HeaderField()),\n+                ('to', ietf.message.models.HeaderField()),\n+                ('cc', ietf.message.models.HeaderField(blank=True)),\n+                ('bcc', ietf.message.models.HeaderField(blank=True)),\n+                ('reply_to', ietf.message.models.HeaderField(blank=True)),\n                 ('body', models.TextField()),\n                 ('content_type', models.CharField(blank=True, default='text/plain', max_length=255)),\n-                ('msgid', models.CharField(blank=True, default=email.utils.make_msgid, max_length=255, null=True)),\n+                ('msgid', ietf.message.models.HeaderField(blank=True, default=email.utils.make_msgid, null=True)),\n                 ('sent', models.DateTimeField(blank=True, null=True)),\n                 ('by', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='person.Person')),\n                 ('related_docs', models.ManyToManyField(blank=True, to='doc.Document')),\ndiff --git a/ietf/message/models.py b/ietf/message/models.py\n--- a/ietf/message/models.py\n+++ b/ietf/message/models.py\n@@ -4,6 +4,7 @@\n \n import email.utils\n \n+from django.forms import TextInput\n from django.db import models\n from django.utils import timezone\n \n@@ -16,19 +17,26 @@\n from ietf.utils.models import ForeignKey\n from ietf.utils.mail import get_email_addresses_from_text\n \n+\n+class HeaderField(models.TextField):\n+    \"\"\"TextField that defaults to a TextInput widget\"\"\"\n+    def formfield(self, **kwargs):\n+        return super().formfield(**{'widget': TextInput, **kwargs})\n+\n+\n class Message(models.Model):\n     time = models.DateTimeField(default=timezone.now)\n     by = ForeignKey(Person)\n \n-    subject = models.CharField(max_length=255)\n-    frm = models.CharField(max_length=255)\n-    to = models.CharField(max_length=1024)\n-    cc = models.CharField(max_length=1024, blank=True)\n-    bcc = models.CharField(max_length=255, blank=True)\n-    reply_to = models.CharField(max_length=255, blank=True)\n+    subject = HeaderField()\n+    frm = HeaderField()\n+    to = HeaderField()\n+    cc = HeaderField(blank=True)\n+    bcc = HeaderField(blank=True)\n+    reply_to = HeaderField(blank=True)\n     body = models.TextField()\n     content_type = models.CharField(default=\"text/plain\", max_length=255, blank=True)\n-    msgid = models.CharField(max_length=255, blank=True, null=True, default=email.utils.make_msgid)\n+    msgid = HeaderField(blank=True, null=True, default=email.utils.make_msgid)\n \n     related_groups = models.ManyToManyField(Group, blank=True)\n     related_docs = models.ManyToManyField(Document, blank=True)\n", "issue": "Handle long email header fields in Message\n### Describe the issue\n\nSeveral 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.\r\n\r\nThese should be `TextField` fields - better to leave deciding the longest reasonable length to the code generating the message.\n\n### Code of Conduct\n\n- [X] I agree to follow the [IETF's Code of Conduct](https://github.com/ietf-tools/.github/blob/main/CODE_OF_CONDUCT.md)\n", "before_files": [{"content": "# Generated by Django 2.2.28 on 2023-03-20 19:22\n\nfrom django.db import migrations, models\nimport django.db.models.deletion\nimport django.utils.timezone\nimport email.utils\nimport ietf.utils.models\n\n\nclass Migration(migrations.Migration):\n\n    initial = True\n\n    dependencies = [\n        ('group', '0001_initial'),\n        ('person', '0001_initial'),\n        ('name', '0001_initial'),\n        ('doc', '0001_initial'),\n    ]\n\n    operations = [\n        migrations.CreateModel(\n            name='Message',\n            fields=[\n                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),\n                ('time', models.DateTimeField(default=django.utils.timezone.now)),\n                ('subject', models.CharField(max_length=255)),\n                ('frm', models.CharField(max_length=255)),\n                ('to', models.CharField(max_length=1024)),\n                ('cc', models.CharField(blank=True, max_length=1024)),\n                ('bcc', models.CharField(blank=True, max_length=255)),\n                ('reply_to', models.CharField(blank=True, max_length=255)),\n                ('body', models.TextField()),\n                ('content_type', models.CharField(blank=True, default='text/plain', max_length=255)),\n                ('msgid', models.CharField(blank=True, default=email.utils.make_msgid, max_length=255, null=True)),\n                ('sent', models.DateTimeField(blank=True, null=True)),\n                ('by', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='person.Person')),\n                ('related_docs', models.ManyToManyField(blank=True, to='doc.Document')),\n                ('related_groups', models.ManyToManyField(blank=True, to='group.Group')),\n            ],\n            options={\n                'ordering': ['time'],\n            },\n        ),\n        migrations.CreateModel(\n            name='SendQueue',\n            fields=[\n                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),\n                ('time', models.DateTimeField(default=django.utils.timezone.now)),\n                ('send_at', models.DateTimeField(blank=True, null=True)),\n                ('sent_at', models.DateTimeField(blank=True, null=True)),\n                ('note', models.TextField(blank=True)),\n                ('by', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='person.Person')),\n                ('message', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='message.Message')),\n            ],\n            options={\n                'ordering': ['time'],\n            },\n        ),\n        migrations.CreateModel(\n            name='MessageAttachment',\n            fields=[\n                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),\n                ('filename', models.CharField(blank=True, db_index=True, max_length=255)),\n                ('content_type', models.CharField(blank=True, max_length=255)),\n                ('encoding', models.CharField(blank=True, max_length=255)),\n                ('removed', models.BooleanField(default=False)),\n                ('body', models.TextField()),\n                ('message', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='message.Message')),\n            ],\n        ),\n        migrations.CreateModel(\n            name='AnnouncementFrom',\n            fields=[\n                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),\n                ('address', models.CharField(max_length=255)),\n                ('group', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='group.Group')),\n                ('name', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='name.RoleName')),\n            ],\n            options={\n                'verbose_name_plural': 'Announcement From addresses',\n            },\n        ),\n        migrations.AddIndex(\n            model_name='sendqueue',\n            index=models.Index(fields=['time'], name='message_sen_time_07ab31_idx'),\n        ),\n        migrations.AddIndex(\n            model_name='message',\n            index=models.Index(fields=['time'], name='message_mes_time_20eabf_idx'),\n        ),\n    ]\n", "path": "ietf/message/migrations/0001_initial.py"}, {"content": "# Copyright The IETF Trust 2012-2020, All Rights Reserved\n# -*- coding: utf-8 -*-\n\n\nimport email.utils\n\nfrom django.db import models\nfrom django.utils import timezone\n\nimport debug                            # pyflakes:ignore\n\nfrom ietf.person.models import Person\nfrom ietf.group.models import Group\nfrom ietf.doc.models import Document\nfrom ietf.name.models import RoleName\nfrom ietf.utils.models import ForeignKey\nfrom ietf.utils.mail import get_email_addresses_from_text\n\nclass Message(models.Model):\n    time = models.DateTimeField(default=timezone.now)\n    by = ForeignKey(Person)\n\n    subject = models.CharField(max_length=255)\n    frm = models.CharField(max_length=255)\n    to = models.CharField(max_length=1024)\n    cc = models.CharField(max_length=1024, blank=True)\n    bcc = models.CharField(max_length=255, blank=True)\n    reply_to = models.CharField(max_length=255, blank=True)\n    body = models.TextField()\n    content_type = models.CharField(default=\"text/plain\", max_length=255, blank=True)\n    msgid = models.CharField(max_length=255, blank=True, null=True, default=email.utils.make_msgid)\n\n    related_groups = models.ManyToManyField(Group, blank=True)\n    related_docs = models.ManyToManyField(Document, blank=True)\n\n    sent = models.DateTimeField(blank=True, null=True)\n\n    class Meta:\n        ordering = ['time']\n        indexes = [\n            models.Index(fields=['time',]),\n        ]\n\n    def __str__(self):\n        return \"'%s' %s -> %s\" % (self.subject, self.frm, self.to)\n\n    def get(self, field):\n        r = getattr(self, field)\n        return r if isinstance(r, list) else get_email_addresses_from_text(r)\n            \n\nclass MessageAttachment(models.Model):\n    message = ForeignKey(Message)\n    filename = models.CharField(max_length=255, db_index=True, blank=True)\n    content_type = models.CharField(max_length=255, blank=True)\n    encoding = models.CharField(max_length=255, blank=True)\n    removed = models.BooleanField(default=False)\n    body = models.TextField()\n\n    def __str__(self):\n        return self.filename\n\n\nclass SendQueue(models.Model):\n    time = models.DateTimeField(default=timezone.now)\n    by = ForeignKey(Person)\n    \n    message = ForeignKey(Message)\n    \n    send_at = models.DateTimeField(blank=True, null=True)\n    sent_at = models.DateTimeField(blank=True, null=True)\n\n    note = models.TextField(blank=True)\n    \n    class Meta:\n        ordering = ['time']\n        indexes = [\n            models.Index(fields=['time',]),\n        ]\n\n    def __str__(self):\n        return \"'%s' %s -> %s (sent at %s)\" % (self.message.subject, self.message.frm, self.message.to, self.sent_at or \"<not yet>\")\n\n\nclass AnnouncementFrom(models.Model):\n    name = ForeignKey(RoleName)\n    group = ForeignKey(Group)\n    address = models.CharField(max_length=255)\n\n    def __str__(self):\n        return self.address\n\n    class Meta:\n        verbose_name_plural='Announcement From addresses'\n        \n", "path": "ietf/message/models.py"}], "after_files": [{"content": "# Generated by Django 2.2.28 on 2023-03-30 19:14\n\nfrom django.db import migrations, models\nimport django.db.models.deletion\nimport django.utils.timezone\nimport email.utils\nimport ietf.message.models\nimport ietf.utils.models\n\n\nclass Migration(migrations.Migration):\n\n    initial = True\n\n    dependencies = [\n        ('group', '0001_initial'),\n        ('person', '0001_initial'),\n        ('name', '0001_initial'),\n        ('doc', '0001_initial'),\n    ]\n\n    operations = [\n        migrations.CreateModel(\n            name='Message',\n            fields=[\n                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),\n                ('time', models.DateTimeField(default=django.utils.timezone.now)),\n                ('subject', ietf.message.models.HeaderField()),\n                ('frm', ietf.message.models.HeaderField()),\n                ('to', ietf.message.models.HeaderField()),\n                ('cc', ietf.message.models.HeaderField(blank=True)),\n                ('bcc', ietf.message.models.HeaderField(blank=True)),\n                ('reply_to', ietf.message.models.HeaderField(blank=True)),\n                ('body', models.TextField()),\n                ('content_type', models.CharField(blank=True, default='text/plain', max_length=255)),\n                ('msgid', ietf.message.models.HeaderField(blank=True, default=email.utils.make_msgid, null=True)),\n                ('sent', models.DateTimeField(blank=True, null=True)),\n                ('by', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='person.Person')),\n                ('related_docs', models.ManyToManyField(blank=True, to='doc.Document')),\n                ('related_groups', models.ManyToManyField(blank=True, to='group.Group')),\n            ],\n            options={\n                'ordering': ['time'],\n            },\n        ),\n        migrations.CreateModel(\n            name='SendQueue',\n            fields=[\n                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),\n                ('time', models.DateTimeField(default=django.utils.timezone.now)),\n                ('send_at', models.DateTimeField(blank=True, null=True)),\n                ('sent_at', models.DateTimeField(blank=True, null=True)),\n                ('note', models.TextField(blank=True)),\n                ('by', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='person.Person')),\n                ('message', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='message.Message')),\n            ],\n            options={\n                'ordering': ['time'],\n            },\n        ),\n        migrations.CreateModel(\n            name='MessageAttachment',\n            fields=[\n                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),\n                ('filename', models.CharField(blank=True, db_index=True, max_length=255)),\n                ('content_type', models.CharField(blank=True, max_length=255)),\n                ('encoding', models.CharField(blank=True, max_length=255)),\n                ('removed', models.BooleanField(default=False)),\n                ('body', models.TextField()),\n                ('message', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='message.Message')),\n            ],\n        ),\n        migrations.CreateModel(\n            name='AnnouncementFrom',\n            fields=[\n                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),\n                ('address', models.CharField(max_length=255)),\n                ('group', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='group.Group')),\n                ('name', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='name.RoleName')),\n            ],\n            options={\n                'verbose_name_plural': 'Announcement From addresses',\n            },\n        ),\n        migrations.AddIndex(\n            model_name='sendqueue',\n            index=models.Index(fields=['time'], name='message_sen_time_07ab31_idx'),\n        ),\n        migrations.AddIndex(\n            model_name='message',\n            index=models.Index(fields=['time'], name='message_mes_time_20eabf_idx'),\n        ),\n    ]\n", "path": "ietf/message/migrations/0001_initial.py"}, {"content": "# Copyright The IETF Trust 2012-2020, All Rights Reserved\n# -*- coding: utf-8 -*-\n\n\nimport email.utils\n\nfrom django.forms import TextInput\nfrom django.db import models\nfrom django.utils import timezone\n\nimport debug                            # pyflakes:ignore\n\nfrom ietf.person.models import Person\nfrom ietf.group.models import Group\nfrom ietf.doc.models import Document\nfrom ietf.name.models import RoleName\nfrom ietf.utils.models import ForeignKey\nfrom ietf.utils.mail import get_email_addresses_from_text\n\n\nclass HeaderField(models.TextField):\n    \"\"\"TextField that defaults to a TextInput widget\"\"\"\n    def formfield(self, **kwargs):\n        return super().formfield(**{'widget': TextInput, **kwargs})\n\n\nclass Message(models.Model):\n    time = models.DateTimeField(default=timezone.now)\n    by = ForeignKey(Person)\n\n    subject = HeaderField()\n    frm = HeaderField()\n    to = HeaderField()\n    cc = HeaderField(blank=True)\n    bcc = HeaderField(blank=True)\n    reply_to = HeaderField(blank=True)\n    body = models.TextField()\n    content_type = models.CharField(default=\"text/plain\", max_length=255, blank=True)\n    msgid = HeaderField(blank=True, null=True, default=email.utils.make_msgid)\n\n    related_groups = models.ManyToManyField(Group, blank=True)\n    related_docs = models.ManyToManyField(Document, blank=True)\n\n    sent = models.DateTimeField(blank=True, null=True)\n\n    class Meta:\n        ordering = ['time']\n        indexes = [\n            models.Index(fields=['time',]),\n        ]\n\n    def __str__(self):\n        return \"'%s' %s -> %s\" % (self.subject, self.frm, self.to)\n\n    def get(self, field):\n        r = getattr(self, field)\n        return r if isinstance(r, list) else get_email_addresses_from_text(r)\n            \n\nclass MessageAttachment(models.Model):\n    message = ForeignKey(Message)\n    filename = models.CharField(max_length=255, db_index=True, blank=True)\n    content_type = models.CharField(max_length=255, blank=True)\n    encoding = models.CharField(max_length=255, blank=True)\n    removed = models.BooleanField(default=False)\n    body = models.TextField()\n\n    def __str__(self):\n        return self.filename\n\n\nclass SendQueue(models.Model):\n    time = models.DateTimeField(default=timezone.now)\n    by = ForeignKey(Person)\n    \n    message = ForeignKey(Message)\n    \n    send_at = models.DateTimeField(blank=True, null=True)\n    sent_at = models.DateTimeField(blank=True, null=True)\n\n    note = models.TextField(blank=True)\n    \n    class Meta:\n        ordering = ['time']\n        indexes = [\n            models.Index(fields=['time',]),\n        ]\n\n    def __str__(self):\n        return \"'%s' %s -> %s (sent at %s)\" % (self.message.subject, self.message.frm, self.message.to, self.sent_at or \"<not yet>\")\n\n\nclass AnnouncementFrom(models.Model):\n    name = ForeignKey(RoleName)\n    group = ForeignKey(Group)\n    address = models.CharField(max_length=255)\n\n    def __str__(self):\n        return self.address\n\n    class Meta:\n        verbose_name_plural='Announcement From addresses'\n        \n", "path": "ietf/message/models.py"}]}