I am writing a simple software that needs to:
Connect to an IMAP server
Download all unread messages
Store each message's body, and attachment. I prefer the body as text.
Mark them as read
I am reading https://github.com/mscdex/node-imap; however, a message can be in multiple parts, and that's where I am lost. For example, when it's multi-part, what is the part that is guaranteed to be the actual email body?
Or, even better, is there a wrapper out there that will just return a nice "message" object, all neatly fetched and prepared for me? Something with the usual headers (from, to, etc.), to body, and a bunch of pre-decoded attachment?
Merc.
To answer the good part of your question: No part is guaranteed to be "the email body", you can legally send a message without text. I've seen software that'll send attachment-only mail when the user adds an attachment but leaves the mail body field empty. The way to distinguish between inline bodies and attachments is to look at the content-disposition field, and if that's not present, assume inline for text/* and attachment for other types. (Yes, this also means that there may be more than one inline body. Apple Mail is fond of sending that, for instance.)
The other part of your question is a FAQ and an easy one, and yes, there's much software to build that message object. Approximately 100% of client libraries can do that. Search your documentation for "bodystructure", that's the name of the IMAP fetch item they retrieve and parse in order to build the structure you want.
Related
An email arrives into a mail-in database. I look at it and see that it has a single Body item, which is Rich Text.
In an agent run after new mail arrives, I want to update the arriving memo, and append some text to that Body item and then save it. I use getfirstitem to get a handle on it, and then use AddNewLine and Appendtext in successive lines of code, adding a bit of text to it, before saving it.
After this is done, I look at the backend document again and where there used to be a single Body item there are now two. Each has a portion of what I expected a single item to have. Between the two, nothing is missing.
Note: The incoming email also has attachments...but it did originally before I updated it and again, there was only one Body item.
Note2: Sending the email from Outlook. How that could be related I don't know.
What could be causing this or what might I do to work around this. Open to all suggestions/ideas.
Thank you
Matt Smith
If you call Compact on the Body after you've finished adding to it (and before saving if you do an explicit save), that might reduce it to a single item, but it's not guaranteed.
There are cases where Body is forced to be 2 or more items. E.g.:
If an email comes in as MIME (which is common for emails from outside your network), each MIME part is always a separate Body item, and there are normally 2 or more MIME parts for a single email.
I think each rich-text item has a strict 64 kB size limit for the raw data, so content exceeding 64 kB will always be 2 or more items, but I'm not sure of this.
As others have said in comments, it's normal to have more than 1 item for rich-text content. You should never have to care about this. If you use GetFirstItem to get a rich-text item and add text to the end of it, it will act like one item from an end-user perspective.
I decided on another way to accomplish what i needed, not appending text, so this question is no longer in need of help, other than to sate my own curiosity. Thanks guys.
I have created a Azure Logic app to read the email body and check for the condition - If the email body 1st line has the only word called "Approved", then trigger another process or else do nothing.
But when performing it, I could see the condition gets to false even though the mail has only Approved word in it accommodated with signatures in the bottom. After researching, I could see the email is being read like HTML tags. So i created two more variable to extract a part of this e-mail and check for condition.
EmailBodyTrimmed = trim(substring(toUpper(replace(replace(trim(variables('EmailBody')),' ',''),'.',''),),0,500))
EmailBodyTrimmedFinal = trim(substring(trim(replace(trim(variables('EmailBodyTrimmed')),' ','')),0,indexOf(replace(variables('EmailBodyTrimmed'),' ',''),'<')))
But nothing seems to give correct answer. Can anyone help me ?
I think you can use Body Preview to receive the body of the email:
According to my test results, it receives the text in non-HTML format, so you don't have to extract the body from the HTML text.
Then you only need to add a condition and use starts with to determine whether it starts with approved.
Of course, this premise is that your email body is in plain text format, if it is in excel format, you need to do other processing.
It seems that docusign only supports downloading the signed documents as PDF instead of JSON.
I need to 'read' the filled fields of the documents (the document has some fields to fill in).
I can upload the document as JSON and it gets parsed, so why can't I donwload it as JSON?
How do companies normally handle the field values?
Thanks!
You don't need the actual PDF document to get the values, you need to parse the call coming back from DocuSign since that has total envelope data. The webhooks for notification contains the data and you can parse that to retrieve the envelope data.
Do you know if its also possible with a GET call instead of the webhook? It could be the server is down etc, so I can't imagine DocuSign does have something like GET:envelope/:id/data or something.. But really cannot find anything like it
Yes. You can either use a GET call (included below) any time you want to get envelope data or you can set up the webhooks so that DocuSign will send you updates whenever it has one!
The following GET call retrieve envelope data from {{envelopeId}}. By parsing the response from the call you can retrieve all information that was filled on the envelope.
{{baseUrl}}/envelopes/{{envelopeId}}/recipients?include_tabs=true
I hope this helps.
P.S. Summarized our comments to have a complete answer.
The PDF format is, for lack of better words, a complicated jumble of compiled data that can be difficult to parse. What it appears docusign will do is take the data provided and fill the PDF document fields that are previously identified.
With docusign returning the PDF, you will need to parse the PDF input fields to receive the field values. There are several libraries that can be used to parse the various form fields and do what you would like. Check out:
https://www.npmjs.com/package/pdfreader
https://www.npmjs.com/package/pdf2json
I am sure there are more that would work for you as well if you look around if these don't work for you.
I saw that Office.context.mailbox.item.body.setSelectedDataAsync() would fail if called with options.coercionType set to Office.CoercionType.Html when the message body is in plain text.
I was wondering if there was any way to check what the format of the message body is before I called setSelectedDataAsync?
You would need to use getTypeAsync method of the body object. Even more, this is suggested way to insert any data into the mail item's body. Before inserting, you should always first verify the supported item format by calling getTypeAsync. Please read more on the topic how to Insert data in the body when composing an appointment or message in Outlook in the Outlook API documentation.
I've got an email processing agent. It copies the body of the email into a document's rich text field. If there are any embedded links in the email I want to process that embedded link and extract the url. I started playing around with MIMEEntity but nothing came of it. Any ideas?
thanks
clem
================
Hi Rich,
Well here's a more robust explanation of what's going on. I have several Notes apps which deal with email correspondence. An email comes in, a Notes document is created with some meta data (system generated ID, user's email, name, company, status, etc). The email body is added to a 'correspondence' rich text field of the created Notes doc. The app allows for someone on our side to follow up on the email (ask a question, provide some feedback, etc). That response from us is pre-pended to the original email. If the original sender responds with some further information, THAT email is also pre-pended. To do this pre-pending, I do
bodyText = EmailDoc.GetFirstItem("Body").text
textFromNotesDoc = CTdoc.GetFirstItem("Issue").text
newTextFromNotesDoc = bodyText + <some stuff> + textFromNotesDoc
I then do a replace.
This worked perfectly fine for years. However, recently users have been sending in emails containing embedded links. Of course anything like that is lost when I do the NotesDocument.GetFirstItem().Text. So I've been trying to think of a way to capture the embedded link. The other day it occurred to me that if I could read the html, I could find and extract the url and simply add it to text. I thought maybe using NotesMIMEEntity would allow me to read through the body field and find the url but that's not working.
Clem
The solution is to NOT NotesDocument.GetFirstItem().Text. Just simply take the email coming in and prepend the body field to the discussion RT field. I add tags to the email going out so that I know if the person responding included the previous conversation. That took a little work to figure out but by using NotesRichTextNavigator and related classes, I'm able to deal with that.
clem