unable to get Yahoo mail by Message-ID using mailkit - imap

I want to fetch mail item by Message-Id using following code.
var messageId = messageIdStringValue.DecryptFromBase64();
var newId = "<" + messageId + ">";
var matches = Client.Inbox.Search(SearchQuery.HeaderContains("Message-ID", newId));
foreach (var uid in matches)
{
var message = Client.Inbox.GetMessage(uid);
}
It's working fine with Gmail by there is no result for Yahoo mail.I should mention that I can get All mail items but the problem is in fetching the single message.Am I doing something wrong?

Thanks to #jstedfast I've found that the best way for searching mail item is by UniqueId not by the Message-ID as the search command maybe return no result in that way for different servers.
following code works fine for all servers:
foreach (var item in Client.Inbox.Fetch(new[] { uId }, MessageSummaryItems.UniqueId | MessageSummaryItems.BodyStructure))
{
var message = Client.Inbox.GetMessage(item.UniqueId)
}

Different IMAP servers implement SEARCH differently.
That said, why are you base64 decoding the message-id value? That doesn't make sense.

Related

Twitter text retrieval with new 280 character system

Using Google Scripts, I have a program that retrieves the text from one account's tweets and uses it for various other things. It's been running for over a year with minimal issues, but now the tweets are being adjusted to 280 characters and I can't retrieve the second half of the tweet. I have:
function refreshing_v2() {
var service = getTwitterService();
if (service.hasAccess()) {
var url = 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=(redacted)&count=1&include_rts=0&exclude_replies=1';
var response = service.fetch(url);
var tweets = JSON.parse(response.getContentText());
for (var i = 0; i < tweets.length; i++) {
//Parse the tweet
var latest = new String(tweets[i].text);
var maxi_id = tweets[i].id;
var startpos = latest.indexOf("1: ");
etc, etc, continues doing stuff with what it's found.
This allows me to get the FIRST half of the text. What's retrieved looks something like "[Content of first half]...(link to tweet)"
How do I get the full text?
You need to add tweet_mode=extended to get the full text in the response. You may need to check the entities you receive to see if it is what you are expecting.
Documentation link - https://developer.twitter.com/en/docs/tweets/tweet-updates
Additionally, you will need to use full_text rather than just text
So:
//Parse the tweet
var latest = new String(tweets[i].full_text);
See the sample tweet at https://github.com/twitterdev/tweet-updates/blob/master/samples/initial/compatibilityplus_extended_13997.json

Associate specific string to a number in google sheets

I am using a google forms to collect responses which I will then use to score people. Unfortunately some of those responses only make sense in a non numeric form, here is an example:
Q: What is your most common mode of transportation?
Car
Carpool
Public transportation
Bike
Walk
I want to be able to have google sheets automatically convert those string responses into a number, as in Car will be 20, carpool 15 and so on so that I can "grade" them and give them a score. Can this be done through google forms? Or maybe some sort of dictionary function?
Thank you!
Another method, requiring no coding, would be to make a worksheet with the encoding of the options and then use VLOOKUP to translate them.
Yep, this can be done through Google Forms. Have a look at https://developers.google.com/apps-script/reference/forms/duration-item#setPoints(Integer)
Using their code, you could go something like
var formResponses = FormApp.getActiveForm().getResponses();
// Go through each form response
for (var i = 0; i < formResponses.length; i++) {
var response = formResponses[i];
var items = FormApp.getActiveForm().getItems();
// Assume it's the first item
var item = items[0];
var itemResponse = response.getGradableResponseForItem(item);
if (itemResponse != null && itemResponse.getResponse() == 'Car') {
var points = item.asMultipleChoiceItem().getPoints();
itemResponse.setScore(points * 20);
// This saves the grade, but does not submit to Forms yet.
response.withItemGrade(itemResponse);
}
}
// Grades are actually submitted to Forms here.
FormApp.getActiveForm().submitGrades(formResponses);

Sequence contains no elements - PayPal SOAP Response

I am trying to read the value from an XML element but I always get "Sequence contains to elements" error.
I already done my research but nothing works for my problem.
I want to read the Ack and Timestamp element values in this XML
<DoDirectPaymentResponse xmlns="urn:ebay:api:PayPalAPI">
<Timestamp xmlns="urn:ebay:apis:eBLBaseComponents">2014-09-16T04:41:56Z</Timestamp>
<Ack xmlns="urn:ebay:apis:eBLBaseComponents">Success</Ack>
</DoDirectPaymentResponse>
Here's my code for reading the Ack and Timestamp values
String xmlString = #xml;
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{
XDocument xdoc = XDocument.Load(reader);
var timestamp = xdoc.Descendants("Timestamp").Single();
receipt.Timestamp = timestamp.Value;
var response = xdoc.Descendants("Ack").Single();
receipt.Response = response.Value;
}
Please help me with this. Thanks a lot.
You need to use proper XNamespace to access elements in the namespace :
XDocument xdoc = XDocument.Parse(xmlString);
XNamespace ns = "urn:ebay:apis:eBLBaseComponents";
var timestamp = xdoc.Descendants(ns+"Timestamp").Single();
receipt.Timestamp = timestamp.Value;
var response = xdoc.Descendants(ns+"Ack").Single();
receipt.Response = response.Value;
Side note: you can use XDocument.Parse() to load XML from XML string content.

Fetching details on an entity in Breeze using Employee('1234')

I want fetch the details of a Collection in Odata services like the following URL
http://my.company.com/odata/Employee('1234')/Details
I tried with the following code to do so. Not sure whether fromEntityKey is the right thing to do or anything else.
manager = new breeze.EntityManager(collectionData.serviceName);
var empType = manager.metadataStore.getEntityType("Employees");
var entityKey = new EntityKey(empType, '1234');
var query = EntityQuery.fromEntityKey(entityKey);
But it gives me an error "Be sure to execute a query or call fetchMetadata first."
I also tried that from this link. But I'm still getting the same.
Can any one help me on this?
You can't use manager.metadataSote.getEntityType("Employees") until metadata has been retrieved from the server. By default this occurs during the first query operation, but your code is attempting to use the metadata before it has been retrieved.
Also, I think that you are confusing the name of your resource "Employees" with the type of the instances returned by your resource, probably "Employee". I would also check whether your key's datatype is numeric or a string. The example below assume its numeric (unlike your example where the datatype of the key is presumably a string because you are quoting it).
So you have two approaches, either force the metadata to be fetched before you compose your query, like this:
manager = new breeze.EntityManager(serviceName);
manager.fetchMetadata().then(function () {
var empType = manager.metadataStore.getEntityType("Employee");
var entityKey = new EntityKey(empType, 1);
var query = EntityQuery.fromEntityKey(entityKey);
// if you want to also see the queries details
query = query.expand("Details");
return manager.executeQuery(query);
}).then(function (data) {
var results = data.results;
ok(results.length === 1, "should have returned a single record");
var emp = results[0];
));
or if you know the string name of the 'key' ("Id" in the example below) field, use it directly
manager = new breeze.EntityManager(serviceName);
var query = EntityQuery.from("Employees")
.where("Id", "==", 1)
.expand("Details");
manager.executeQuery(query).then(function(data) {
var results = data.results;
var emp = results[0];
});

How to parse multiple nodes of html using HtmlAgilityPack?

I'd appreciate if someone could help! I'm trying to parse the following page of Groupon website http://www.groupon.com/browse/chicago?category=activities-and-nightlife
var webGet = new HtmlWeb();
var deal1 = webGet.Load("http://www.groupon.com/browse/chicago?category=activities-and-nightlife");
I want to get the whole block of each Deal(i.e. offer for discount)
HtmlNodeCollection content_block = deal1.DocumentNode.SelectNodes("//div[#class = 'deal-list-tile grid_5_third']");
Then out of each block i want to get title, company name, location and price.
foreach(HtmlNode node in content_block)
{
string title2 = node.SelectSingleNode("//div[#class = 'deal-title js-permalink']").InnerText;
string country2 = node.SelectSingleNode("//p[#class = 'merchant-name']").InnerText;
string location2 = node.SelectSingleNode("//p[#class = 'location']").InnerText;
string price2 = node.SelectSingleNode("//div[#class = 'price']/span").InnerText;
}
Here i get confused, i need to write all the information about deals into
DbSet<Deal> Deals , but even if i try to display the content as ViewBag.Message = title + country + location + price; i get System.NullReferenceException: Object reference not set to an instance of an object in the line with content_block.
What am i doing wrong =(
Thanks in advance!
The problem appears to be that the selectnodes returns nothing or null when no nodes are found instead of an empty collection. so this means you should probably wrap if (content_block != null) { around your code block above.

Resources