Skip to content

Fixes "similar-code" issue in sendgrid/helpers/mail/mail.py #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions sendgrid/helpers/mail/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,13 @@ def get(self):
if self.template_id is not None:
mail["template_id"] = self.template_id

if self.sections is not None:
sections = {}
for key in self.sections:
sections.update(key.get())
mail["sections"] = sections

if self.headers is not None:
headers = {}
for key in self.headers:
headers.update(key.get())
mail["headers"] = headers

select(self.sections,"sections")
select(self.headers,"headers")
if self.categories is not None:
mail["categories"] = [category.get() for category in
self.categories]

if self.custom_args is not None:
custom_args = {}
for key in self.custom_args:
custom_args.update(key.get())
mail["custom_args"] = custom_args
select(self.custom_args,"custom_args")

if self.send_at is not None:
mail["send_at"] = self.send_at
Expand All @@ -105,6 +91,13 @@ def get(self):
mail["reply_to"] = self.reply_to.get()
return mail

def select(data,index):
if data is not None:
container = {}
for key in data:
container.update(key.get())
mail[index] = container

@property
def from_email(self):
return self._from_email
Expand Down