Today's Menu  Portugal
journal and plan nutrition
Instance Methods | List of all members
M9MailServerNavigator Class Reference

#import <M9MailServerNavigator.h>

Inheritance diagram for M9MailServerNavigator:
Inheritance graph
[legend]
Collaboration diagram for M9MailServerNavigator:
Collaboration graph
[legend]

Instance Methods

(instancetype) - init:
 
(void) - initializeBlockedList
 
(void) - rcvdNutriJournInfoHeadersWithTicket:finishedWithObject:error: [implementation]
 
(Boolean) - isDoNotDowloadListed: [implementation]
 
(void) - rcvdMessageWithTicket:finishedWithObject:error: [implementation]
 
(void) - rcvdAttachmentWithTicket:finishedWithObject:error: [implementation]
 

Detailed Description

Definition at line 12 of file M9MailServerNavigator.h.

Method Documentation

◆ init:()

- (instancetype) init: (Y3GmailViewController *)  d

Definition at line 26 of file M9MailServerNavigator.m.

27 {
28  self = [super init];
29  if (self) {
30  delegate = d;
31 
32  mesgTickets = [[NSMutableArray alloc] init];
33 
34  msgNearDateFormatter = [[NSDateFormatter alloc] init];
35  msgNearDateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
36  msgNearDateFormatter.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss ZZZZZ";
37  msgNearDateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:8];
38  eMsgAttachments = [[NSMutableDictionary alloc] initWithCapacity:20];
39 
40  Z5GmailDataController *mailControl = [[[Z5DataController sharedInstance] remoteDataController] emailController];
41  [mailControl addDataListener:self];
42 
43  doNotDownloadMessages = [[NSMutableArray alloc] init];
44  }
45  return self;
46 }
NSMutableDictionary * eMsgAttachments
instancetype sharedInstance()
NSMutableArray< EmailMessage * > * doNotDownloadMessages
id< U7ParamEditControlDelegate > delegate
void addDataListener:(id< Z5GmailDataListener > ear)
NSMutableArray< GTLRServiceTicket * > * mesgTickets
Singleton interface to both core and remote data sources.
NSDateFormatter * msgNearDateFormatter
Fetch all marked emails into the local database, and display a list.

◆ initializeBlockedList()

- (void) initializeBlockedList

Definition at line 78 of file M9MailServerNavigator.m.

79 {
80  [doNotDownloadMessages removeAllObjects];
81 }

◆ isDoNotDowloadListed:()

- (Boolean) isDoNotDowloadListed: (GTLRGmail_Message *)  mesg
implementation

Definition at line 82 of file M9MailServerNavigator.m.

82  :(GTLRGmail_Message *) mesg
83 {
84  Boolean ret = NO;
85  if (0 == [doNotDownloadMessages count]) {
86  Z5LocalDataController *localData = [[Z5DataController sharedInstance] localDataController];
87  NSArray<EmailMessage *> *dbEmail = [localData retrieveAllEmailMessages];
88 
89  [doNotDownloadMessages addObjectsFromArray:dbEmail];
90  }
91  for (EmailMessage *emsg in doNotDownloadMessages) {
92  // NSLog(@"GmailViewController.isDoNotDowloadListed: identifier: %@ remoteUniqueIID: %@", mesg.identifier, emsg.remoteUniqueIID);
93  if ([emsg.remoteUniqueIID isEqualToString:mesg.identifier]) {
94  ret = YES;
95  // NSLog(@"GmailViewController.isDoNotDowloadListed: BREAK");
96  break;
97  }
98  }
99  return ret;
100 }
instancetype sharedInstance()
NSMutableArray< EmailMessage * > * doNotDownloadMessages
Singleton interface to both core and remote data sources.

◆ rcvdAttachmentWithTicket:finishedWithObject:error:()

- (void) rcvdAttachmentWithTicket: (GTLRServiceTicket *)  callbackTicket
finishedWithObject: (GTLRObject *)  object
error: (NSError *)  callbackError 
implementation

Definition at line 190 of file M9MailServerNavigator.m.

190  :(GTLRServiceTicket *)callbackTicket finishedWithObject:(GTLRObject *)object error:(NSError *)callbackError
191 {
193  if (nil == callbackError) {
194  // object is GTLRGmail_MessagePartBody
195  NSString *messageID = callbackTicket.ticketProperties[@"Message ID"];
196  assert(messageID);
197  EmailMessage *eMsg = [eMsgAttachments objectForKey:messageID];
198  [eMsgAttachments removeObjectForKey:messageID];
199 
200  GTLRGmail_MessagePartBody *partBody = (GTLRGmail_MessagePartBody *)object;
201 
202 
203  NSString *encodedStr = partBody.data;
204  NSString *identitiyNumber = partBody.attachmentId;
205  // NSLog(@"GmailViewController.rcvdInfoMessage: image-str: %@", encodedStr);
206  if (nil != encodedStr) {
207  NSData *intermediateData = [mainCntrlr googleBase64Data:partBody.data];
208  [eMsg setPhoto:intermediateData];
209  // UIImage *msgImage = [UIImage imageWithData:intermediateData];
210  } else if (nil != identitiyNumber) {
211  NSLog(@"GmailViewController.rcvdInfoMessage: attachmentId:%@", identitiyNumber);
212  } else {
213  NSLog(@"GmailViewController.rcvdInfoMessage: nil partBody data and attachID");
214  }
215  } else {
216  NSLog(@"GmailViewController.rcvdAttachmentWithTicket: error: %@", callbackError.localizedDescription);
217  }
218 }
NSData * googleBase64Data:(NSString *googEncodeString)
instancetype sharedInstance()
Singleton interface to both core and remote data sources.

◆ rcvdMessageWithTicket:finishedWithObject:error:()

- (void) rcvdMessageWithTicket: (GTLRServiceTicket *)  ticket
finishedWithObject: (GTLRGmail_Message *)  message
error: (NSError *)  error 
implementation

this method will be called for every message found in the search for message headers.

Definition at line 104 of file M9MailServerNavigator.m.

104  :(GTLRServiceTicket *)ticket
105  finishedWithObject:(GTLRGmail_Message *)message
106  error:(NSError *)error {
108  Z5GmailDataController *eMailCntrlr = [[mainCntrlr remoteDataController] emailController];
109  if (error == nil) {
110  Z5LocalDataController *localData = [[Z5DataController sharedInstance] localDataController];
111  // have string message.identifier, not NSNumber
112  EmailMessage *eMsg = [localData findOrCreateEmailMessageWithFileIdentification:message.identifier];
113  NSLog(@"Y3GmailViewController.rcvdMessageWithTicket: %@", message.identifier);assert(eMsg);
114  [emailMessages addObject:eMsg];
115  [mesgTickets removeObject:ticket];
116  NSArray<GTLRGmail_MessagePartHeader *> *hdrs = message.payload.headers;
117  for (GTLRGmail_MessagePartHeader *headInfo in hdrs) {
118  if ([@"Subject" isEqualToString:headInfo.name]) {
119  // NSLog(@"GmailViewController.rcvdInfoMessage: subject: %@", headInfo.value);
120  [eMsg setSubject:headInfo.value];
121  }
122  }
123  NSLog(@"GmailDisplayController.rcvdMessageWithTicket - headers");
124  for (GTLRGmail_MessagePartHeader *headInfo in hdrs) {
125  NSLog(@" %@ / %@", headInfo.name, headInfo.value);
126  if ([@"Message-Id" isEqualToString:headInfo.name]) {
127  [eMsg setUid:headInfo.value];
128  }
129  if ([@"From" isEqualToString:headInfo.name]) {
130  [eMsg setFrom:headInfo.value];
131  }
132  if ([@"Date" isEqualToString:headInfo.name]) {
133  /* 39 minutes and 57 seconds after the 16th hour of December 19th, 1996 with an offset of -08:00 from UTC (Pacific Standard Time)
134  NSString *string = @"1996-12-19T16:39:57-08:00"; */
135  NSDate *date = [msgNearDateFormatter dateFromString:headInfo.value];
136  // NSLog(@"GmailDisplayController.rcvdInfoMessage:\nDate In: %@\nDate out: %@", headInfo.value, date);
137  // NSLog(@"GmailDisplayController.rcvdInfoMessage:\n Is Now: %@", [msgNearDateFormatter stringFromDate:[NSDate dateWithTimeIntervalSinceNow:0]]);
138  [eMsg setDate:date];
139  }
140  if ([@"Subject" isEqualToString:headInfo.name]) {
141  [eMsg setSubject:headInfo.value];
142  }
143  }
144 
145 
146  NSArray <GTLRGmail_MessagePart *> *msgPts = message.payload.parts;
147  for (GTLRGmail_MessagePart *msgPt in msgPts) {
148  NSLog(@"GmailViewController.rcvdInfoMessage: mime-type: %@", msgPt.mimeType);
149  if ([@"image/jpeg" isEqualToString:msgPt.mimeType]) {
150 
151  // nil?
152  NSLog(@"GmailViewController.rcvdInfoMessage: image filename: %@", msgPt.filename);
153 
154  if (nil == msgPt.filename) {
155  NSData *partData = [mainCntrlr googleBase64Data:msgPt.body.data];
156  // UIImage *msgImage = [UIImage imageWithData:partData];
157  [eMsg setPhoto:partData];
158  } else {
159  NSString *attId = msgPt.body.attachmentId;
160  GTLRServiceTicket *attachmentTicket = [eMailCntrlr fetchMessageAttachment:attId onMessage:message.identifier withListener:self];
161  NSLog(@"GmailViewController.rcvdInfoMessage: attachmentTicket %@", attachmentTicket.description);
162 
163  [eMsgAttachments setValue:eMsg forKey:message.identifier];
164  }
165  } else if ([@"text/html" isEqualToString:msgPt.mimeType]) {
166 
167  NSData *intermediateData = [mainCntrlr googleBase64Data:msgPt.body.data];
168  NSString *decodeString = [[NSString alloc] initWithData:intermediateData encoding:NSUTF8StringEncoding];
169 
170  NSLog(@" html: %@", decodeString);
171  [eMsg setBodyhtml:decodeString];
172  } else if ([@"text/plain" isEqualToString:msgPt.mimeType]) {
173 
174  NSData *intermediateData = [mainCntrlr googleBase64Data:msgPt.body.data];
175  NSString *decodeString = [[NSString alloc] initWithData:intermediateData encoding:NSUTF8StringEncoding];
176 
177  // NSLog(@" plain: %@", decodeString);
178  [eMsg setBodytext:decodeString];
179  }
180  }// END - for all parts of the message
181  } else {
182  // [self showAlert:@"Error" message:error.localizedDescription];
183  }
184  // NSLog(@"rcvdMessageWithTicket: outstanding tickets: %ld", [mesgTickets count]);
185  if (0 == [mesgTickets count]) {
186  [delegate reframeTable];
187  }
188 }
NSData * googleBase64Data:(NSString *googEncodeString)
Z5GmailDataController * emailController
instancetype sharedInstance()
NSMutableArray< GTLRServiceTicket * > * mesgTickets
Singleton interface to both core and remote data sources.
EmailMessage * findOrCreateEmailMessageWithFileIdentification:(NSString *googlefileid)
Z5RemoteDataController * remoteDataController
GTLRServiceTicket * fetchMessageAttachment:onMessage:withListener:(NSString *identifier, [onMessage] NSString *msgId, [withListener] id< Z5GmailDataListener > listener)

◆ rcvdNutriJournInfoHeadersWithTicket:finishedWithObject:error:()

- (void) rcvdNutriJournInfoHeadersWithTicket: (GTLRServiceTicket *)  ticket
finishedWithObject: (GTLRGmail_ListMessagesResponse *)  messagesResponse
error: (NSError *)  error 
implementation

Definition at line 50 of file M9MailServerNavigator.m.

50  :(GTLRServiceTicket *)ticket
51  finishedWithObject:(GTLRGmail_ListMessagesResponse *)messagesResponse
52  error:(NSError *)error {
53  Z5GmailDataController *eMailCntrlr = [[[Z5DataController sharedInstance] remoteDataController] emailController];
54  if (error == nil) {
55  NSLog(@"GmailViewController.rcvdInfoHeaders: header count: %lu", messagesResponse.messages.count);
56  // NSMutableString *labelString = [[NSMutableString alloc] init];
57  if (messagesResponse.messages.count > 0) {
58  // [labelString appendString:@"Messages:\n"];
59  for (GTLRGmail_Message *mesg in messagesResponse.messages) {
60 
61  // Check that message is not one on do-not-download list
62  if ([self isDoNotDowloadListed:mesg]) {
63  NSLog(@"GmailViewController.rcvdInfoHeaders: download blocked");
64  } else {
65  GTLRServiceTicket *ticket = [eMailCntrlr fetchJournalMessage:mesg.identifier withListener:self];
66  [mesgTickets addObject:ticket];
67  }
68  }
69  } else {
70  // [labelString appendString:@"No messages found."];
71  NSLog(@"GmailViewController.rcvdInfoHeaders: no messages found");
72  }
73  } else {
74  NSLog(@"GmailViewController.rcvdInfoHeaders: error: %@", error.localizedDescription);
75  }
76 }
instancetype sharedInstance()
GTLRServiceTicket * fetchJournalMessage:withListener:(NSString *identifier, [withListener] id< Z5GmailDataListener > listener)
Singleton interface to both core and remote data sources.

The documentation for this class was generated from the following files: