mirror of
https://github.com/GAM-team/GAM.git
synced 2026-06-29 18:31:38 +00:00
Clean up sendOrDropEmail (#961)
* Clean up sendOrDropEmail * Date allowed in all commands, only sets kwargs for import/insert * Two updates Allow headers in draft/import/insert/send email Quote arguments in todrive decscription * Make requested changes * Don't user sendser as an alias for from as they can be different things in SMTP * On import message, default to not checking for spam
This commit is contained in:
@@ -945,12 +945,12 @@ gam calendar <CalendarItem> showacl
|
|||||||
gam calendar <CalendarItem> printacl [todrive]
|
gam calendar <CalendarItem> printacl [todrive]
|
||||||
|
|
||||||
<EventNotificationAttribute> ::=
|
<EventNotificationAttribute> ::=
|
||||||
notifyattendees|(sendnotifications <Boolean>)|(sendupdates all|enternalonly|none)
|
notifyattendees|(sendnotifications <Boolean>)|(sendupdates all|enternalonly|none)
|
||||||
|
|
||||||
The following attributes are equivalent:
|
The following attributes are equivalent:
|
||||||
notifyattendees - sendupdates all
|
notifyattendees - sendupdates all
|
||||||
sendnotifications false - sendupdates none
|
sendnotifications false - sendupdates none
|
||||||
sendnotifications true - sendupdates all
|
sendnotifications true - sendupdates all
|
||||||
|
|
||||||
<EventAttributes> ::=
|
<EventAttributes> ::=
|
||||||
anyonecanaddself|
|
anyonecanaddself|
|
||||||
@@ -976,15 +976,15 @@ The following attributes are equivalent:
|
|||||||
(visibility default|public|prvate)
|
(visibility default|public|prvate)
|
||||||
|
|
||||||
<EventSelectProperty:> ::=
|
<EventSelectProperty:> ::=
|
||||||
(after <Time>)|
|
(after <Time>)|
|
||||||
(before <Time>)|
|
(before <Time>)|
|
||||||
includeeleted|
|
includeeleted|
|
||||||
includehidden|
|
includehidden|
|
||||||
(query <QueryCalendar>)|
|
(query <QueryCalendar>)|
|
||||||
(updatedmin <Time>)
|
(updatedmin <Time>)
|
||||||
|
|
||||||
<EventDisplayProperty> ::=
|
<EventDisplayProperty> ::=
|
||||||
(timezone <TimeZone>)
|
(timezone <TimeZone>)
|
||||||
|
|
||||||
gam calendar <CalendarItem> addevent <EventAttributes>+ [<EventNotificationAttribute>]
|
gam calendar <CalendarItem> addevent <EventAttributes>+ [<EventNotificationAttribute>]
|
||||||
gam calendar <CalendarItem> deleteevent id|eventid <EventID> [doit] [<EventNotificationAttribute>]
|
gam calendar <CalendarItem> deleteevent id|eventid <EventID> [doit] [<EventNotificationAttribute>]
|
||||||
@@ -1286,10 +1286,20 @@ gam <UserTypeEntity> untrash messages query <QueryGmail> [doit] [max_to_untrash|
|
|||||||
|
|
||||||
gam <UserTypeEntity> show gmailprofile [todrive]
|
gam <UserTypeEntity> show gmailprofile [todrive]
|
||||||
|
|
||||||
gam <UserTypeEntity> draftemail [recipient <EmailAddress>] [subject <String>] [(message <String>)|(file <FileName> [charset <Charset>])]
|
gam <UserTypeEntity> draftemail [recipient|to <EmailAddress>] [from <EmailAddress>]
|
||||||
gam <UserTypeEntity> importemail [recipient <EmailAddress>] [subject <String> [(message <String>)|(file <FileName> [charset <Charset>])]]
|
[subject <String>] [(message <String>)|(file <FileName> [charset <Charset>])]
|
||||||
gam <UserTypeEntity> insertemail [recipient <EmailAddress>] [subject <String>] [(message <String>)|(file <FileName> [charset <Charset>])]
|
gam <UserTypeEntity> importemail [recipient|to <EmailAddress>] [from <EmailAddress>]
|
||||||
gam <UserTypeEntity> sendemail [recipient <EmailAddress>] [subject <String>] [(message <String>)|(file <FileName> [charset <Charset>])]
|
[subject <String>] [(message <String>)|(file <FileName> [charset <Charset>])]
|
||||||
|
[labels <LabelNameList>] (header <String> <String>)*
|
||||||
|
[deleted] [date <Time>]
|
||||||
|
[nevercheckspam] [processforcalendar]
|
||||||
|
gam <UserTypeEntity> insertemail [recipient|to <EmailAddress>] [from <EmailAddress>]
|
||||||
|
[subject <String>] [(message <String>)|(file <FileName> [charset <Charset>])]
|
||||||
|
[labels <LabelNameList>] (header <String> <String>)*
|
||||||
|
[deleted] [date <Time>]
|
||||||
|
gam <UserTypeEntity> sendemail [recipient|to <EmailAddress>] [from <EmailAddress>]
|
||||||
|
[subject <String>] [(message <String>)|(file <FileName> [charset <Charset>])]
|
||||||
|
(header <String> <String>)*
|
||||||
|
|
||||||
gam <UserTypeEntity> create|add delegate|delegates <EmailAddress>
|
gam <UserTypeEntity> create|add delegate|delegates <EmailAddress>
|
||||||
gam <UserTypeEntity> delegate|delegates to <EmailAddress>
|
gam <UserTypeEntity> delegate|delegates to <EmailAddress>
|
||||||
|
|||||||
55
src/gam.py
55
src/gam.py
@@ -5348,6 +5348,11 @@ def sendOrDropEmail(users, method='send'):
|
|||||||
body = subject = ''
|
body = subject = ''
|
||||||
recipient = labels = sender = None
|
recipient = labels = sender = None
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
|
if method in ['insert', 'import']:
|
||||||
|
kwargs['internalDateSource'] = 'receivedTime'
|
||||||
|
if method == 'import':
|
||||||
|
kwargs['neverMarkSpam'] = True
|
||||||
|
msgHeaders = {}
|
||||||
i = 4
|
i = 4
|
||||||
while i < len(sys.argv):
|
while i < len(sys.argv):
|
||||||
myarg = sys.argv[i].lower().replace('_', '')
|
myarg = sys.argv[i].lower().replace('_', '')
|
||||||
@@ -5361,38 +5366,35 @@ def sendOrDropEmail(users, method='send'):
|
|||||||
elif myarg == 'subject':
|
elif myarg == 'subject':
|
||||||
subject = sys.argv[i+1]
|
subject = sys.argv[i+1]
|
||||||
i += 2
|
i += 2
|
||||||
elif myarg == 'recipient':
|
elif myarg in ['recipient', 'to']:
|
||||||
recipient = sys.argv[i+1]
|
recipient = sys.argv[i+1]
|
||||||
i += 2
|
i += 2
|
||||||
elif myarg == 'sender':
|
elif myarg == 'from':
|
||||||
sender = sys.argv[i+1]
|
sender = sys.argv[i+1]
|
||||||
i += 2
|
i += 2
|
||||||
elif myarg == 'labels':
|
elif myarg == 'header':
|
||||||
labels = sys.argv[i+1].split(',')
|
msgHeaders[sys.argv[i+1]] = sys.argv[i+2]
|
||||||
|
i += 3
|
||||||
|
elif method in ['insert', 'import'] and myarg == 'labels':
|
||||||
|
labels = shlexSplitList(sys.argv[i+1])
|
||||||
i += 2
|
i += 2
|
||||||
elif myarg == 'deleted':
|
elif method in ['insert', 'import'] and myarg == 'deleted':
|
||||||
if method not in ['insert', 'import']:
|
|
||||||
systemErrorExit(3, 'deleted is only valid on insertemail and importemail')
|
|
||||||
kwargs['deleted'] = True
|
kwargs['deleted'] = True
|
||||||
i += 1
|
i += 1
|
||||||
elif myarg == 'receivednow':
|
elif myarg == 'date':
|
||||||
if method not in ['insert', 'import']:
|
msgHeaders['Date'] = getTimeOrDeltaFromNow(sys.argv[i+1])
|
||||||
systemErrorExit(3, 'received_now is only valid on insertemail and importemail')
|
if method in ['insert', 'import']:
|
||||||
kwargs['internalDateSource'] = 'receivedTime'
|
kwargs['internalDateSource'] = 'dateHeader'
|
||||||
i += 1
|
i += 2
|
||||||
elif myarg == 'checkspam':
|
elif method == 'import' and myarg == 'checkspam':
|
||||||
if method not in ['import']:
|
|
||||||
systemErrorExit(3, 'check_spam is only valid on importemail')
|
|
||||||
kwargs['neverMarkSpam'] = False
|
kwargs['neverMarkSpam'] = False
|
||||||
i += 1
|
i += 1
|
||||||
elif myarg == 'checkcalendar':
|
elif method == 'import' and myarg == 'processforcalendar':
|
||||||
if method not in ['import']:
|
|
||||||
systemErrorExit(3, 'check_calendar is only valid on importemail')
|
|
||||||
kwargs['processForCalendar'] = True
|
kwargs['processForCalendar'] = True
|
||||||
else:
|
else:
|
||||||
systemErrorExit(2, '%s is not a valid argument for "gam <users> sendemail"' % sys.argv[i])
|
systemErrorExit(2, '%s is not a valid argument for "gam <users> %semail"' % (sys.argv[i], method))
|
||||||
for user in users:
|
for user in users:
|
||||||
send_email(subject, body, recipient, sender, user, method, labels, kwargs)
|
send_email(subject, body, recipient, sender, user, method, labels, msgHeaders, kwargs)
|
||||||
|
|
||||||
def doImap(users):
|
def doImap(users):
|
||||||
enable = getBoolean(sys.argv[4], 'gam <users> imap')
|
enable = getBoolean(sys.argv[4], 'gam <users> imap')
|
||||||
@@ -10950,17 +10952,15 @@ def doDeleteOrg():
|
|||||||
print("Deleting organization %s" % name)
|
print("Deleting organization %s" % name)
|
||||||
callGAPI(cd.orgunits(), 'delete', customerId=GC_Values[GC_CUSTOMER_ID], orgUnitPath=encodeOrgUnitPath(makeOrgUnitPathRelative(name)))
|
callGAPI(cd.orgunits(), 'delete', customerId=GC_Values[GC_CUSTOMER_ID], orgUnitPath=encodeOrgUnitPath(makeOrgUnitPathRelative(name)))
|
||||||
|
|
||||||
def send_email(subject, body, recipient=None, sender=None, user=None, method='send', labels=None, kwargs={}):
|
def send_email(subject, body, recipient=None, sender=None, user=None, method='send', labels=None, msgHeaders={}, kwargs={}):
|
||||||
api_body = {}
|
api_body = {}
|
||||||
default_sender = default_recipient = False
|
default_sender = default_recipient = False
|
||||||
if not user:
|
if not user:
|
||||||
user = _getValueFromOAuth('email')
|
user = _getValueFromOAuth('email')
|
||||||
userId, gmail = buildGmailGAPIObject(user)
|
userId, gmail = buildGmailGAPIObject(user)
|
||||||
resource = gmail.users().messages()
|
resource = gmail.users().messages()
|
||||||
if labels and method in ['insert', 'import']:
|
if labels:
|
||||||
api_body['labelIds'] = labelsToLabelIds(gmail, labels)
|
api_body['labelIds'] = labelsToLabelIds(gmail, labels)
|
||||||
elif labels:
|
|
||||||
systemErrorExit(3, 'labels argument is only valid for importemail and insertemail')
|
|
||||||
if not sender:
|
if not sender:
|
||||||
sender = userId
|
sender = userId
|
||||||
default_sender = True
|
default_sender = True
|
||||||
@@ -10968,6 +10968,7 @@ def send_email(subject, body, recipient=None, sender=None, user=None, method='se
|
|||||||
recipient = userId
|
recipient = userId
|
||||||
default_recipient = True
|
default_recipient = True
|
||||||
msg = message_from_string(body)
|
msg = message_from_string(body)
|
||||||
|
msg.update(msgHeaders)
|
||||||
if subject:
|
if subject:
|
||||||
del msg['Subject']
|
del msg['Subject']
|
||||||
msg['Subject'] = subject
|
msg['Subject'] = subject
|
||||||
@@ -10986,7 +10987,6 @@ def send_email(subject, body, recipient=None, sender=None, user=None, method='se
|
|||||||
method = 'create'
|
method = 'create'
|
||||||
api_body = {'message': api_body}
|
api_body = {'message': api_body}
|
||||||
elif method in ['insert', 'import']:
|
elif method in ['insert', 'import']:
|
||||||
kwargs['internalDateSource'] = 'dateHeader'
|
|
||||||
if method == 'import':
|
if method == 'import':
|
||||||
method = 'import_'
|
method = 'import_'
|
||||||
callGAPI(resource, method, userId=userId, body=api_body, **kwargs)
|
callGAPI(resource, method, userId=userId, body=api_body, **kwargs)
|
||||||
@@ -11051,6 +11051,9 @@ def sortCSVTitles(firstTitle, titles):
|
|||||||
for title in restoreTitles[::-1]:
|
for title in restoreTitles[::-1]:
|
||||||
titles.insert(0, title)
|
titles.insert(0, title)
|
||||||
|
|
||||||
|
def QuotedArgumentList(items):
|
||||||
|
return ' '.join([item if item and (item.find(' ') == -1) and (item.find(',') == -1) else '"'+item+'"' for item in items])
|
||||||
|
|
||||||
def writeCSVfile(csvRows, titles, list_type, todrive):
|
def writeCSVfile(csvRows, titles, list_type, todrive):
|
||||||
def rowDateTimeFilterMatch(dateMode, rowDate, op, filterDate):
|
def rowDateTimeFilterMatch(dateMode, rowDate, op, filterDate):
|
||||||
if not rowDate or not isinstance(rowDate, str):
|
if not rowDate or not isinstance(rowDate, str):
|
||||||
@@ -11155,7 +11158,7 @@ and follow recommend steps to authorize GAM for Drive access.''' % (admin_email)
|
|||||||
mimeType = 'text/csv'
|
mimeType = 'text/csv'
|
||||||
else:
|
else:
|
||||||
mimeType = MIMETYPE_GA_SPREADSHEET
|
mimeType = MIMETYPE_GA_SPREADSHEET
|
||||||
body = {'description': ' '.join(sys.argv),
|
body = {'description': QuotedArgumentList(sys.argv),
|
||||||
'name': '%s - %s' % (GC_Values[GC_DOMAIN], list_type),
|
'name': '%s - %s' % (GC_Values[GC_DOMAIN], list_type),
|
||||||
'mimeType': mimeType}
|
'mimeType': mimeType}
|
||||||
result = callGAPI(drive.files(), 'create', fields='webViewLink',
|
result = callGAPI(drive.files(), 'create', fields='webViewLink',
|
||||||
|
|||||||
Reference in New Issue
Block a user