forked from sendgrid/sendgrid-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader.py
More file actions
85 lines (69 loc) · 2.4 KB
/
header.py
File metadata and controls
85 lines (69 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
try:
import json
except ImportError:
import simplejson as json
class SmtpApiHeader(object):
def __init__(self):
self.data = {}
def add_to(self, to):
if 'to' not in self.data:
self.data['to'] = []
if type(to) is str:
self.data['to'] += [to]
else:
self.data['to'] += to
def add_cc(self, cc):
if 'cc' not in self.data:
self.data['cc'] = []
if type(cc) is str:
self.data['cc'] += [cc]
else:
self.data['cc'] += cc
def add_bcc(self, bcc):
if 'bcc' not in self.data:
self.data['bcc'] = []
if type(bcc) is str:
self.data['bcc'] += [bcc]
else:
self.data['bcc'] += bcc
def set_replyto(self, replyto):
self.data['reply_to'] = replyto
def add_sub_val(self, var, val):
if 'sub' not in self.data:
self.data['sub'] = {}
if type(val) is str:
self.data['sub'][var] = [val]
else:
self.data['sub'][var] = val
def set_unique_args(self, val):
if type(val) is dict:
self.data['unique_args'] = val
def add_unique_arg(self, key, val):
if 'unique_args' not in self.data:
self.data['unique_args'] = {}
self.data['unique_args'][key] = val
def set_category(self, cat):
self.data['category'] = [cat]
def add_category(self, cat):
if 'category' not in self.data:
self.data['category'] = []
self.data['category'].append(cat)
def add_section(self, key, section):
if 'section' not in self.data:
self.data['section'] = {}
self.data['section'][key] = section
def set_section(self, val):
self.data['section'] = val
def add_filter_setting(self, fltr, setting, val):
if 'filters' not in self.data:
self.data['filters'] = {}
if fltr not in self.data['filters']:
self.data['filters'][fltr] = {}
if 'settings' not in self.data['filters'][fltr]:
self.data['filters'][fltr]['settings'] = {}
self.data['filters'][fltr]['settings'][setting] = val
def as_json(self):
return json.dumps(self.data)
def as_string(self):
str = 'X-SMTPAPI: %s' % self.as_json()
return str