06. Training – Part 3 [11:35]

Description: This video explains the following:

  1. How to move mail
  2. How to display mail
  3. How to get the default Mac Mail account
  4. How to delete mail


In this video we’re going to look at how you Move Mail Records, Display Mail Records, Get the default MacMail Account, and Delete Mail Records, all using FileMaker scripts steps and our plug-in function calls.

0:22 Let’s begin by looking at how we Move Mail, the functions involved in order to move mail across your MacMail folders are PCMM_OpenAccount( Name) as you have to insure that you have your account open, OpenFolder to insure that you have the folder open, OpenRecord to ensure that you have the record open that you would like to move, and lastly, MoveRecord. The MoveRecord function moves the currently opened MacMail item from its current folder to another folder. Let’s open FileMaker and take a look at the script steps involved in moving a record. Here’s my demo file in FileMaker. Before I begin I’ll go ahead and refresh my account list, and as you can see in MacMail I currently have two mail accounts set up. I’m going to select Melinda – then I will navigate to the Mail tab, I’m going to refresh the folder list here and that’s going to gather a list of all of my folders that are contained in my Melinda MacMail account and I’m going to select my Inbox/Al folder and I will import all of the emails from the Inbox/Al folder first; just so we have some data to work with. We’re going to discuss importing mail in another video, but for the sake of this demonstration purpose, we do need to have some emails in our FileMaker solution all ready. Once I’ve imported an email I could then go and look at let’s say this first email right here, and if we go to the Move Mail tab here at the top I have the current folder that the mail resides in.
And as you can see here’s my unique Mac Mail ID right here and also the date that I received the email. What I’m going to do is select a destination folder, and lets just actually go down and how about we set the Inbox/Core as the folder that we’re going to work with. So what’s going to happen, and I’ll open up Debugger in just a moment, is we’re going to trigger the Move Mail script and that’s going to move this mail record that is identified by this mail ID from the Inbox/Al folder to my Inbox/Core folder. Let’s just go ahead and open up my MacMail for just a moment so you can see here that if we were to go the Inbox/Core folder I do not have any emails in there, it’s completely empty. Let’s navigate back to my demo file and I will go ahead and open up Debugger and I’m going to select Move Mail and I’ll put the Data Viewer here back to back and we’re going to perform the script called Move Mail and I’m actually just going to go ahead and skip over these are some checker scripts that we have here that we run in our demo file. So I’ll just play through to this marker here, and then what we’re going to do is first insuring that the destination folder is valid and not empty. Then we’re going to validate the existence of the mail ID; these are just FileMaker script steps I’m not introducing any Plug-in functions yet. Next we’re going to go ahead and open up the account and again this is specifying the Melinda account as you saw previously on the set up tab. Then we’re going to open the folder that we’re working with, and if we keep scrolling down now we are opening the record, and the record is identified by the unique MacMail ID that we actually do put right on that demo interface, and you can see here the ID shown in Data Viewer as well. And lastly we’re going to call the MoveRecord function, and this MoveRecord function is actually going to move the mail record to the folder destination, which as you can see the folder destination over here is the Inbox/Core. And we have proper error trapping throughout so if any of these plug-in functions encounter an error then we call our GetLastError function, right here, you can see that throughout
our scripts in our demo file. And then if we scroll down we actually show a custom dialog here that we have successfully moved this mail to the Inbox/Core folder. And if I am to close out of Data Viewer and script Debugger I can now see that the current folder that the mail item resides is the Inbox/Core, we show you that in our demo here. And if I navigate to MacMail here is my Inbox/Core folder and there you can see is the email from Al that has been successfully moved. I’m just going to move that record back.

4:58And now let’s go ahead and take a look at the second item here, and that is how we display mail. This is going to display the current active message in MacMail and what we’re going to do is look at the functions here used to display mail. First we need to insure, of course, that we have an account that we are working with and call the OpenAccount function, then we need to open the specified folder where the mail record resides that we’re working with, then we’re going to actually open the record using the unique MacMailID for that record in that folder. And lastly we call the Display function and we pass the MacMailID to display that message and bring it right to the forefront. Let’s go ahead in FileMaker and go back to our demo file, and why don’t we just work with this mail record that were working with, and let’s go to the Mail tab here and this record we know exists in MacMail and this message resides in my Inbox/Al folder because we did actually put it back. Let’s go ahead and show you how you display this in MacMail. So we’re going to go to script Debugger and simply select the Display in Mail button, open our Data Viewer, and what we’ll do is we’ll just again skip over all of these checker scripts that we have here, and we’re just first in our demo we’re checking to make sure we actually have a valid MacMail ID. And then we’re going to open the account that we want to work with and open the folder, open the record, and lastly we are going to call the Display function, and as soon as we do that it actually brings the MacMail message to the forefront on our computer. It’s a really convenient function that you can add in to give your users just a little smoother interface, so if they actually want to bring a MacMail message to the forefront without having to rummage through this folder and MacMail and this mail record it just pops it right open to the forefront. And then we’re now viewing the record in MacMail as you can see. Just close this and let’s go back to FileMaker you can just play through that, close Debugger and Data Viewer, go ahead and close that there.

7:03 And let’s take a look at our third item which is how to get the default account; which is simply using one function called PCMM_GetFirstAccount. And let’s navigate back to our FileMaker demo file; we’ve added this on the Other Functions tab. And if we go ahead and open up Debugger and simply call GetDefaultAccount and that’s going to call the GetDefaultAccount script, and when we play through this let’s go ahead again and put our marker down here so we skip over those checker scripts. Simply calling GetFirstAccount retrieves the first account here and there’s the value its PCI-Melinda and we actually do show that in a custom dialog here for the user, so you can see that. This is just an additional function that we’ve added that can be quite handy when developing. If we were to go ahead and open up our preferences you can see I have two accounts PCI-Melinda and PCI-Support, if I were to move Support to the top PCI-Support is now going to be my first account or my default account. And let’s go ahead and show you that. We could actually just put the function name in here pcmm_getfirstaccount and let’s go ahead and evaluate that and you can see my first account now is PCI-Support. If I were to go back and let’s change my first account or default account back to Melinda and then go into FileMaker and call this function again my default account is now Melinda.

8:34 Lastly we’re going to discuss how you Delete Records. The functions involved for deleting a record are OpenAccount, of course we need to know the account we’re working with in MacMail, OpenFolder, OpenRecord, and then we have the DeleteRecord function. The DeleteRecord function is going to delete the record in the currently open folder. Now that record can either be the current record selected or it can be another record in the current folder referenced by its MacMail ID. We also have the DeleteAllRecords function and that function is going to delete all records from the current folder. This is really a soft delete and it’s really going to move all records into your MacMail trash folder. And then we also have the EmptyAllDeletedItems function and this function is going to remove all items from the deleted items folder in your MacMail, now keep in mind it’s going to delete any items that you’ve moved using the DeleteRecord function and it’s going to remove all the objects that the user moved there manually. So you really need to make sure you’re using the DeleteRecord options with caution so you don’t permanently delete your user’s mail. Let’s go into our demo file here and we’ll go work with this record here from Al that we were using previously. And let’s go ahead and open up Debugger, going to click the red Delete in MacMail button, open the Data Viewer and I’ll go to the current tab there and what we’ll do is again skip over all of the demo checker scripts that we run. And first thing we’re just going to check for a mail ID, then of course here we are opening our current account, opening our folder, opening the record and then we get to the function called DeleteRecord here. So this DeleteRecord is then going to delete the record, and you could also show a dialog there that deletion was successful, we just show a dialog if an error occurs as you can see here as we’re properly trapping for errors after each of our plug-in function calls. Let’s go ahead and open up MacMail and let’s see if that record indeed was deleted, if we go into the Al’s folder here, I no longer see that record that we were looking at. And if were to go into my trash can here there is the record that was actually moved to the trash can, so I could then have a subsequent call to empty all deleted items and that’s actually going to empty all my deleted items there.

This wraps up the other features that are available by the plug-in. I encourage you to watch the other training videos and documentation, and reverse engineer the Demo file. If you have questions drop us an email, give us a phone call, or browse our forum if you have any additional questions. We look forward to hearing from you and thank you for watching.