Delete Exchange 2003 Emails with WebDav - exchange-server

I am trying to manage an Inbox in Exchange 2003 automatically using webdav from a C# application. Looking at msdn is not helping me a whole lot as the methods described here (http://msdn.microsoft.com/en-us/library/aa142917.aspx) do not coincide at all with the samples I have found otherwise. So there are two things I am trying to determine:
Of all the fields that return from a webdav query
string reqStr =
#"<?xml version=""1.0""?>
<g:searchrequest xmlns:g=""DAV:"">
<g:sql>
SELECT
*
FROM
""http://server/Exchange/email1#domain.com/Inbox/""
WHERE ""urn:schemas:mailheader:from"" = 'email2#domain.com'
</g:sql>
</g:searchrequest>";
Which one is the unique identifier? I have browsed it (but not sure of a reference to verify the fields) and it appears at first glance that DAV:id is what I want (), but I am not wanting to work on assumptions.
Secondly, what is the correct way to programmatically delete an email after I have processed it? Would something like the following work (will it remove the entry and all related metadata). I don't want any files left orphaned on the server...
string reqStr =
#"<?xml version=""1.0""?>
<g:searchrequest xmlns:g=""DAV:"">
<g:sql>
DELETE
FROM
""http://server/Exchange/email1#domain.com/Inbox/""
WHERE ""DAV:id"" = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'
</g:sql>
</g:searchrequest>";
And finally, what are the best online sources for investigating all the data returned in the XML from the first request, and where are all the options documented for managing the webdav interface? Looking at MSDN just hasn't been fruitful.

Look for the dav:hef tags tag in the response. They contain an url you can use to issue a delete command.

From the result of a query that gets you the msg Uri then:
var request = (HttpWebRequest)WebRequest.Create(mail.MailUri);
request.Credentials = _credential;
request.Method = "DELETE";
var response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode != HttpStatusCode.OK)
{
//something might of broke
}

Related

UniqueBody empty when Body is not

I have inherited responsibility for a project from a previous developer which takes incoming emails and processes them into customer support tickets.
It mostly works fine but it is having problems with one particular email and I can't work out why.
In Outlook the email clearly has a body (some short text, an image and a signature). It is a new message and not a reply.
The exchange server version is 2013.
But when being processed by the code below UniqueBody is empty, while Body contains the correct text. This does not happen with any other emails I've come across on that server.
if (serverVersion >= ExchangeVersion.Exchange2010)
body = msg.UniqueBody.Text;
else
body = msg.Body.Text;
What would cause UniqueBody to be empty while Body is not?
Why would the previous developer prefer to use UniqueBody over Body, how do they differ?
Could be related to this?
Check if you request the properties correctly:
PropertySet ps = new PropertySet(ItemSchema.UniqueBody);
var email = EmailMessage.Bind(service, item.ItemId, ps);
If you do so, the UniqueBody-Property should not be empty.
As far as I know, UniqueBody should be set by the exchange-server to show you which part of the mail is relevant for your ticket:
https://msdn.microsoft.com/en-us/library/office/dd877075(v=exchg.150).aspx
If your customer answers later to the ticket-conversation, you only want the new text.
With a new mail/ticket: body == uniqueBody == "the text you want to use".

Get a message's ts value from /archives link

Slack has a Copy link feature, which copies a deep link to an individual chat message to the clipboard:
Here's an example of such a deep link (obfuscated):
https://myworkspace.slack.com/archives/CqwertGU/p1234567898000159
What I'd like to do is, get the details of that message from the Slack API given that link.
The first string after /archives/ is the channel's ID. I'm not quite clear about that second string though:
According to Slack's API documentation,
channels.history can also be used to pluck a single message from the
archive.
You'll need a message's ts value, uniquely identifying it within a
channel. You'll also need that channel's ID.
So, what I've found is that the p1234567898000159 value in the link above is almost the message's ts value, but not quite (the Slack API won't accept it): the leading p needs to be removed, also there has to be a . inserted after the 10th digit: 1234567898.000159
Putting all this together into an API request...
https://slack.com/api/channels.history?latest=1234567898.000159&channel=CqwertGU&count=1&pretty=1&token=mytoken123&inclusive=true
... I'm getting a response with all the message details, exactly what I need.
My question is: am I doing this right? Do I really need to craft the message's ts value from the URL parameter this way, or is there a better, more robust, officially supported way?
Im new in python, but i got same problem when i creating SlackBot (by SlackBolt), and i solved it like that:
link = 'https://***.slack.com/archives/C03UGEVQ6BX/p1668769293636169'
#Grab information from link
wrong_link_list = link.split('/')
wrong_ts = wrong_link_list[-1]
t_ts = wrong_ts.replace('p', '', 1)
dot = '.'
char_count = 10
#Put information in variables
channel = wrong_link_list[-2]
text = 'Hey dude!'
mess_ts = t_ts[:char_count] + dot + t_ts[char_count:]
app.client.chat_postMessage(channel=channel, text=text, thread_ts = mess_ts)
Hope this will help you!

Windows Phone webclient caching "issue"?

I am trying to call the same link, but with different values, the issue is that the url is correct containing the new values but when I download it (Webclient.DownloadStringTaskAsync), it gives me the previous calls result.
I have tried adding headers no-cache, and attaching a random value to the call, and ifmodifiedSince header. however it is still not working.
any help will be much appreciated cause I have tried everything.
uri: + "&junk=" + Guid.NewGuid());
client.Headers["Cache-Control"] = "no-cache";
client.Headers[HttpRequestHeader.IfModifiedSince] = DateTime.UtcNow.ToString();
var accessdes = await client.DownloadStringTaskAsync(uri3);
so here my uri3 contains the latest values, but when I hover over accessdes, it contains the result as if I am making a old uri3 call with previous set data.
I saw one friend that was attaching a random GUID to the Url in order to prevent the OS to cache its content. For example:
if the Url were: http://www.ms.com/getdatetime and the OS is caching it.
Our solution was adding a guid for creating "sort of" like a new url, as an example our previous Url would look like: http://www.ms.com/getdatetime?cachebuster=21EC2020-3AEA-4069-A2DD-08002B30309D
(see more about cache buster : http://www.adopsinsider.com/ad-ops-basics/what-is-a-cache-buster-and-how-does-it-work/ )

Outlook 2007 Add-In - mailItem.To only available after hitting a breakpoint and looking at value manually

I am making an outlook plugin in visual studio and part of it requires gathering the recipients/subject/body content. I am able to gather the subject and body without problem but accessing mailItem.To I always find it's blank.
body = mailItem.Body
subject = mailItem.Subject
Dim readtest As String = mailItem.To
Is the code I am using, and what makes it worse is that if I put a breakpoint in before trying to populate readtest and then I manually just look at the mailItem.To value and resume or step through the code it will work just fine.
Does anyone know how I can get this working properly?
You could try to get the same functionality with mailItem.Recipients property.
It returns IEnumerable. Recipient object have a Name member so basically you could do the following (It's in C# but i think you could figure it out with vb):
string recipients = string.Empty;
foreach (Outlook.Recipient r in mailItem.Recipients)
{
recipients += r.Name + ";";
}
You should get the same result as if you use mailItem.To

Google Spreadsheet API - returns remote 500 error

Has anyone battled 500 errors with the Google spreadsheet API for google domains?
I have copied the code in this post (2-legged OAuth): http://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/OAuth/Program.cs, substituted in my domain;s API id and secret and my own credentials, and it works.
So it appears my domain setup is fine (at least for the contacts/calendar apis).
However swapping the code out for a new Spreadsheet service / query instead, it reverts to type: remote server returned an internal server error (500).
var ssq = new SpreadsheetQuery();
ssq.Uri = new OAuthUri("https://spreadsheets.google.com/feeds/spreadsheets/private/full", "me", "mydomain.com");
ssq.OAuthRequestorId = "me#mydomain.com"; // can do this instead of using OAuthUri for queries
var feed = ssservice.Query(ssq); //boom 500
Console.WriteLine("ss:" + feed.Entries.Count);
I are befuddled
I had to make sure to use the "correct" class:
not
//using SpreadsheetQuery = Google.GData.Spreadsheets.SpreadsheetQuery;
but
using SpreadsheetQuery = Google.GData.Documents.SpreadsheetQuery;
stinky-malinky
Seems you need the gdocs api to query for spreadsheets, but the spreadsheet api to query inside of a spreadsheet but nowhere on the internet until now will you find this undeniably important tit-bit. Google sucks hard on that one.

Resources