Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Email Message source #143

Closed
guderkar opened this issue Dec 23, 2016 · 9 comments
Closed

Get Email Message source #143

guderkar opened this issue Dec 23, 2016 · 9 comments
Assignees
Milestone

Comments

@guderkar
Copy link

guderkar commented Dec 23, 2016

Hello I wonder if there is a way to get message source like this in one piece of string

Received: from exchange.guderkar.com ([fe80::45a:8d31:b6dc:6cd3]) by
 exchange.guderkar.com ([fe80::45a:8d31:b6dc:6cd3%11]) with mapi; Fri, 16 Dec
 2016 22:31:03 +0100
From: tracy <tracy@guderkar.com>
To: student <student@guderkar.com>
Subject: attach
Thread-Topic: attach
Thread-Index: AQHSV+Ozi/jvgwEPmUiaIJZu/kQUYQ==
Date: Fri, 16 Dec 2016 21:31:02 +0000
Message-ID: <1481923862.7232.0.camel@guderkar.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 04
X-MS-Exchange-Organization-AuthSource: exchange.guderkar.com
X-MS-Has-Attach: yes
X-MS-Exchange-Organization-SCL: -1
X-MS-TNEF-Correlator:
Content-Type: multipart/mixed;
	boundary="_002_148192386272320camelguderkarcom_"
MIME-Version: 1.0

--_002_148192386272320camelguderkarcom_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

attach=

--_002_148192386272320camelguderkarcom_
Content-Type: application/javascript; name="test.js"
Content-Description: test.js
Content-Disposition: attachment; filename="test.js"; size=140;
	creation-date="Fri, 16 Dec 2016 21:31:02 GMT";
	modification-date="Fri, 16 Dec 2016 21:31:02 GMT"
Content-ID: <c5ab3c9c-a0e7-47c6-9504-5e8b03e60d4e>
Content-Transfer-Encoding: base64

Zm9yICh2YXIgaSA9IDA7IGkgPCBwcm9jZXNzLmFyZ3YubGVuZ3RoOyBpKyspCgljb25zb2xlLmxv
Zyhwcm9jZXNzLmFyZ3ZbaV0pOw==

--_002_148192386272320camelguderkarcom_--

Right now I can somehow compose the source myself, but this would save me lot of troubles. Thanks.

EDIT: I think I need MimeContent and TextBody, but I can't find a way to load them

item.Load(new ews.PropertySet(ews.BasePropertySet.FirstClassProperties,
                         ews.ItemSchema.TextBody,
                         ews.ItemSchema.MimeContent)).then(function() 
{
    process.stdout.write(item.MimeContent + '\n');
});
@gautamsi
Copy link
Owner

have you tried exporting items using ews? it should give you exactly what you are looking for.

Note: in this library any c# byte[] (email.MimeContent.Content in this case) or stream is base64 string, you have to convert to Buffer or convert from base64 before saving to disk or displaying to screen

@guderkar
Copy link
Author

Yeah thats what I need but still I don't know how to load MimeContent property, in the example above the item.MimeContent returns null;

@gautamsi
Copy link
Owner

can you post your code? I can fix it for this library, I have to work on documentation which I am not able to do due to time constraints.

you want to initialize PropertySet like this new ews.PropertySet(ews.BasePropertySet.IdOnly, [ews.ItemSchema.MimeContent]) I have to fix the c# way of initializer before 1.0

@guderkar
Copy link
Author

var adinationalProps = [];
adinationalProps.push(ews.ItemSchema.MimeContent);
adinationalProps.push(ews.ItemSchema.TextBody);

var Promise = require('bluebird');
var items = exch.FindItems(ews.WellKnownFolderName.Inbox, new ews.ItemView());

items.then(function (response) {
    Promise.reduce(response.Items,function(totalNotUsed, item){
        return item.Load(new ews.PropertySet(ews.BasePropertySet.FirstClassProperties, adinationalProps)).then(function() {
            process.stdout.write(item.MimeContent.Content + '\n');
            return null;
        });
    }, null).then(function(totalNotUsed) {
        //all done
    });
});

but this end with 'Unhandled rejection (<{"InnerException":null,"message":"The ...>, no stack trace)'
which is bluebird report

@gautamsi
Copy link
Owner

what is the full message? bluebird complains about non Error object in rejection, it is known issue. I am going to transform soapfault class to service exception (which extends Error) in errors before 1.0

@guderkar
Copy link
Author

There is no other message.

var adinationalProps = [];
adinationalProps.push(ews.ItemSchema.MimeContent);
adinationalProps.push(ews.ItemSchema.TextBody);

var items = exch.FindItems(ews.WellKnownFolderName.Inbox, new ews.ItemView());
items.then(function (response) {
    for ( var item of response.Items )
    {
    	item.Load(new ews.PropertySet(ews.BasePropertySet.FirstClassProperties, adinationalProps)).then(function() {
    		console.log(item.Subject);
    		console.log(item.MimeContent);
    		console.log("----------------------");
    	});
    }
});

The problem is that when I do item.Load(new ews.PropertySet(ews.BasePropertySet.FirstClassProperties, adinationalProps)) the function is not even called. But when I remove adinational props item.Load(new ews.PropertySet(ews.BasePropertySet.FirstClassProperties)) it is called correctly.

@gautamsi
Copy link
Owner

gautamsi commented Dec 23, 2016

I have ran this exactly by your example, I have no problem getting MimeContent.Content. I see there is a bug for TextBody which will be fixed in next release.

@guderkar
Copy link
Author

Had no clue TextBody was causing the problem. I got it working now. Thank you!!

@gautamsi
Copy link
Owner

for your requirement, no need to use FirstClassProperties as you may not need all of them, IdOnly is sufficient for BasePropertySet. Just use ItemSchema.MimeContent

@gautamsi gautamsi added this to the 0.9.0 milestone Jun 16, 2017
@gautamsi gautamsi self-assigned this Jun 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants