Skip to content
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

Moved mail helper classes into separate files #472

Merged
merged 1 commit into from
Oct 28, 2017
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion sendgrid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .version import __version__ # noqa
# v3 API
from .sendgrid import SendGridAPIClient # noqa
from .helpers.mail.mail import Email # noqa
from .helpers.mail import Email # noqa
23 changes: 22 additions & 1 deletion sendgrid/helpers/mail/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
from .mail import * # noqa
from .asm import ASM
from .attachment import Attachment
from .bcc_settings import BCCSettings
from .bypass_list_management import BypassListManagement
from .category import Category
from .click_tracking import ClickTracking
from .content import Content
from .custom_arg import CustomArg
from .email import Email
from .footer_settings import FooterSettings
from .ganalytics import Ganalytics
from .header import Header
from .mail_settings import MailSettings
from .mail import Mail
from .open_tracking import OpenTracking
from .personalization import Personalization
from .sandbox_mode import SandBoxMode
from .section import Section
from .spam_check import SpamCheck
from .subscription_tracking import SubscriptionTracking
from .substitution import Substitution
from .tracking_settings import TrackingSettings
36 changes: 36 additions & 0 deletions sendgrid/helpers/mail/asm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class ASM(object):

def __init__(self, group_id=None, groups_to_display=None):
self._group_id = None
self._groups_to_display = None

if group_id is not None:
self._group_id = group_id

if groups_to_display is not None:
self._groups_to_display = groups_to_display

@property
def group_id(self):
return self._group_id

@group_id.setter
def group_id(self, value):
self._group_id = value

@property
def groups_to_display(self):
return self._groups_to_display

@groups_to_display.setter
def groups_to_display(self, value):
self._groups_to_display = value

def get(self):
asm = {}
if self.group_id is not None:
asm["group_id"] = self.group_id

if self.groups_to_display is not None:
asm["groups_to_display"] = self.groups_to_display
return asm
66 changes: 66 additions & 0 deletions sendgrid/helpers/mail/attachment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class Attachment(object):

def __init__(self):
self._content = None
self._type = None
self._filename = None
self._disposition = None
self._content_id = None

@property
def content(self):
return self._content

@content.setter
def content(self, value):
self._content = value

@property
def type(self):
return self._type

@type.setter
def type(self, value):
self._type = value

@property
def filename(self):
return self._filename

@filename.setter
def filename(self, value):
self._filename = value

@property
def disposition(self):
return self._disposition

@disposition.setter
def disposition(self, value):
self._disposition = value

@property
def content_id(self):
return self._content_id

@content_id.setter
def content_id(self, value):
self._content_id = value

def get(self):
attachment = {}
if self.content is not None:
attachment["content"] = self.content

if self.type is not None:
attachment["type"] = self.type

if self.filename is not None:
attachment["filename"] = self.filename

if self.disposition is not None:
attachment["disposition"] = self.disposition

if self.content_id is not None:
attachment["content_id"] = self.content_id
return attachment
37 changes: 37 additions & 0 deletions sendgrid/helpers/mail/bcc_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class BCCSettings(object):

def __init__(self, enable=None, email=None):
self._enable = None
self._email = None

if enable is not None:
self.enable = enable

if email is not None:
self.email = email

@property
def enable(self):
return self._enable

@enable.setter
def enable(self, value):
self._enable = value

@property
def email(self):
return self._email

@email.setter
def email(self, value):
self._email = value

def get(self):
bcc_settings = {}
if self.enable is not None:
bcc_settings["enable"] = self.enable

if self.email is not None:
email = self.email.get()
bcc_settings["email"] = email["email"]
return bcc_settings
21 changes: 21 additions & 0 deletions sendgrid/helpers/mail/bypass_list_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class BypassListManagement(object):

def __init__(self, enable=None):
self._enable = None

if enable is not None:
self.enable = enable

@property
def enable(self):
return self._enable

@enable.setter
def enable(self, value):
self._enable = value

def get(self):
bypass_list_management = {}
if self.enable is not None:
bypass_list_management["enable"] = self.enable
return bypass_list_management
17 changes: 17 additions & 0 deletions sendgrid/helpers/mail/category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Category(object):

def __init__(self, name=None):
self._name = None
if name is not None:
self._name = name

@property
def name(self):
return self._name

@name.setter
def name(self, value):
self._name = value

def get(self):
return self.name
36 changes: 36 additions & 0 deletions sendgrid/helpers/mail/click_tracking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class ClickTracking(object):

def __init__(self, enable=None, enable_text=None):
self._enable = None
self._enable_text = None

if enable is not None:
self.enable = enable

if enable_text is not None:
self.enable_text = enable_text

@property
def enable(self):
return self._enable

@enable.setter
def enable(self, value):
self._enable = value

@property
def enable_text(self):
return self._enable_text

@enable_text.setter
def enable_text(self, value):
self._enable_text = value

def get(self):
click_tracking = {}
if self.enable is not None:
click_tracking["enable"] = self.enable

if self.enable_text is not None:
click_tracking["enable_text"] = self.enable_text
return click_tracking
36 changes: 36 additions & 0 deletions sendgrid/helpers/mail/content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Content(object):

def __init__(self, type_=None, value=None):
self._type = None
self._value = None

if type_ is not None:
self.type = type_

if value is not None:
self.value = value

@property
def type(self):
return self._type

@type.setter
def type(self, value):
self._type = value

@property
def value(self):
return self._value

@value.setter
def value(self, value):
self._value = value

def get(self):
content = {}
if self.type is not None:
content["type"] = self.type

if self.value is not None:
content["value"] = self.value
return content
33 changes: 33 additions & 0 deletions sendgrid/helpers/mail/custom_arg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class CustomArg(object):

def __init__(self, key=None, value=None):
self._key = None
self._value = None

if key is not None:
self.key = key

if value is not None:
self.value = value

@property
def key(self):
return self._key

@key.setter
def key(self, value):
self._key = value

@property
def value(self):
return self._value

@value.setter
def value(self, value):
self._value = value

def get(self):
custom_arg = {}
if self.key is not None and self.value is not None:
custom_arg[self.key] = self.value
return custom_arg
62 changes: 62 additions & 0 deletions sendgrid/helpers/mail/email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
class Email(object):

def __init__(self, email=None, name=None):
self._name = None
self._email = None
if name or email:
if not name:
# allows passing emails as "dude Fella <[email protected]>"
self.parse_email(email)
else:
#allows backwards compatibility for Email(email, name)
if email is not None:
self.email = email
self.name = name

@property
def name(self):
return self._name

@name.setter
def name(self, value):
self._name = value

@property
def email(self):
return self._email

@email.setter
def email(self, value):
self._email = value

def get(self):
email = {}
if self.name is not None:
email["name"] = self.name

if self.email is not None:
email["email"] = self.email
return email

def parse_email(self, email_info):
try:
import rfc822
except ImportError:
import email.utils as rfc822

name, email = rfc822.parseaddr(email_info)

# more than likely a string was passed here instead of an email address
if "@" not in email:
name = email
email = None

if not name:
name = None

if not email:
email = None

self.name = name
self.email = email
return name, email
Loading