Skip to content

Commit

Permalink
bounce handling for #166
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Aug 18, 2024
1 parent 7f98e07 commit a63da3c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 17 deletions.
18 changes: 18 additions & 0 deletions auctions/migrations/0141_auctiontos_email_address_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.8 on 2024-08-18 18:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('auctions', '0140_auction_advanced_lot_adding_alter_auction_buy_now_and_more'),
]

operations = [
migrations.AddField(
model_name='auctiontos',
name='email_address_status',
field=models.CharField(blank=True, choices=[('BAD', 'Invalid'), ('UNKNOWN', 'Unknown'), ('VALID', 'Verified')], default='UNKNOWN', max_length=20),
),
]
49 changes: 42 additions & 7 deletions auctions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,17 @@ class AuctionTOS(models.Model):
selling_allowed = models.BooleanField(default=True, blank=True)
name = models.CharField(max_length=181, null=True, blank=True)
email = models.EmailField(null=True, blank=True)
EMAIL_ADDRESS_STATUSES = (
('BAD', 'Invalid'),
('UNKNOWN', "Unknown"),
('VALID', 'Verified'),
)
email_address_status = models.CharField(
max_length=20,
choices=EMAIL_ADDRESS_STATUSES,
default="UNKNOWN",
blank=True
)
phone_number = models.CharField(max_length=20, blank=True, null=True)
address = models.CharField(max_length=500, blank=True, null=True)
manually_added = models.BooleanField(default=False, blank=True, null=True)
Expand Down Expand Up @@ -3275,6 +3286,19 @@ def save(self, *args, **kwargs):
subscription.save()
super().save(*args, **kwargs)

@property
def unsubscribe_from_all(self):
self.email_me_about_new_auctions = False
self.email_me_about_new_local_lots = False
self.email_me_about_new_lots_ship_to_location = False
self.email_me_when_people_comment_on_my_lots = False
self.email_me_about_new_chat_replies = False
self.send_reminder_emails_about_joining_auctions = False
self.email_me_about_new_in_person_auctions = False
self.has_unsubscribed = True
self.last_activity = timezone.now()
self.save()

class UserInterestCategory(models.Model):
"""
How interested is a user in a given category
Expand Down Expand Up @@ -3689,18 +3713,29 @@ def bounce_handler(sender, mail_obj, bounce_obj, raw_message, *args, **kwargs):
#message_id = mail_obj['messageId']
recipient_list = mail_obj['destination']
print("Mail bounced")
print(mail_obj)
try:
print(recipient_list[0])
except:
email = recipient_list[0]
print(email)
auctiontos = AuctionTOS.objects.filter(email=email)
for tos in auctiontos:
tos.email_address_status="BAD"
tos.save()
except Exception as e:
print(e)
print(recipient_list)
print(mail_obj)

@receiver(complaint_received)
def complaint_handler(sender, mail_obj, complaint_obj, raw_message, *args, **kwargs):
recipient_list = mail_obj['destination']
print("Mail complaint")
print(mail_obj)
try:
print(recipient_list[0])
except:
print(recipient_list)
print(mail_obj)
email = recipient_list[0]
print(email)
#user = User.objects.filter(email=email).first()
#if user:
# user.userdata.unsubscribe_from_all
except Exception as e:
print(e)
print(recipient_list)
11 changes: 1 addition & 10 deletions auctions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4393,16 +4393,7 @@ def get_context_data(self, **kwargs):
if not userData:
raise Http404
else:
userData.email_me_about_new_auctions = False
userData.email_me_about_new_local_lots = False
userData.email_me_about_new_lots_ship_to_location = False
userData.email_me_when_people_comment_on_my_lots = False
userData.email_me_about_new_chat_replies = False
userData.send_reminder_emails_about_joining_auctions = False
userData.email_me_about_new_in_person_auctions = False
userData.has_unsubscribed = True
userData.last_activity = timezone.now()
userData.save()
userData.unsubscribe_from_all
context = super().get_context_data(**kwargs)
return context

Expand Down

0 comments on commit a63da3c

Please sign in to comment.