-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
backend/mlarchive/archive/migrations/0003_fix_message_msgid.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Generated by Django 4.2.13 on 2024-05-16 22:18 | ||
|
||
from django.db import migrations | ||
import hashlib | ||
import base64 | ||
|
||
|
||
def get_hash(msg): | ||
"""Returns the message hashcode, a SHA-1 digest of the Message-ID and listname. | ||
Similar to the popular Web Email Archive, mail-archive.com | ||
see: https://www.mail-archive.com/faq.html#msgid | ||
""" | ||
msgid = msg.msgid.encode('utf8') | ||
listname = msg.email_list.name.encode('utf8') | ||
sha = hashlib.sha1(msgid) | ||
sha.update(listname) | ||
b64 = base64.urlsafe_b64encode(sha.digest()) | ||
return b64.decode('utf8') | ||
|
||
|
||
def forward(apps, schema_editor): | ||
Message = apps.get_model('archive', 'Message') | ||
|
||
msgs = Message.objects.filter(msgid__startswith=' ') | ||
for m in msgs: | ||
msgid = m.msgid | ||
fixed_msgid = msgid.lstrip().lstrip('<') | ||
m.msgid = fixed_msgid | ||
m.spam_score = 20240516 | ||
m.hashcode = get_hash(m) | ||
m.save() | ||
|
||
def reverse(apps, schema_editor): | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("archive", "0002_alter_message_msgid"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(forward, reverse), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters