Coverage for fix_folders.py: 0%
22 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-05 09:19 +0800
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-05 09:19 +0800
1"""Script to fix email folders"""
2import os
3import sys
4import django
6# Setup Django
7os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
8sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
9django.setup()
11from django.db import connection
13cursor = connection.cursor()
15acc_id = 'bb97f5aaf5e744049533fd1c84640084'
16tenant_id = '7231bde9e867484faf5eef08ac2ac68d'
18print('Fixing folders for account:', acc_id)
20cursor.execute("DELETE FROM email_emailfolder WHERE id = 2")
21print('Deleted duplicate INBOX (id=2)')
23folders = [
24 ('Sent', 'sent', 'sent'),
25 ('Drafts', 'draft', 'draft'),
26 ('Trash', 'trash', 'trash'),
27 ('Spam', 'spam', 'spam'),
28 ('Outbox', 'outbox', 'outbox'),
29]
31for name, ftype, remote_id in folders:
32 cursor.execute(
33 "INSERT INTO email_emailfolder (created_at, updated_at, tenant_id, name, remote_id, folder_type, unread_count, account_id) VALUES (datetime('now'), datetime('now'), %s, %s, %s, %s, 0, %s)",
34 (tenant_id, name, remote_id, ftype, acc_id)
35 )
36 print('Created:', name)
38cursor.execute('SELECT id, name, folder_type, account_id FROM email_emailfolder ORDER BY account_id, folder_type')
39print()
40print('All folders:')
41for f in cursor.fetchall():
42 print(' Account:', f[3], 'Name:', f[1], 'Type:', f[2])