how javamail imap fetch mail order by receive date desc? folder.getMessage() no a date arg.
I want to sort by date when fetch mail in imap.
Thanks Advance!
Normally, messages are stored in the INBOX in the order they're received, so message number order is received date order. But note that this can be wrong if messages are moved between folders.
In general, if you want messages in a particular order, you'll need to sort them. If your IMAP server supports the SORT extension, you can ask the server to do the sorting by using the com.sun.mail.imap.IMAPFolder.getSortedMessages method.
#DefaultValue("REVERSE,ARRIVAL") MailSortTerms sortTerms
/**/
if (imapStore.hasCapability("SORT*")) {
Message[] messages = ((IMAPFolder) inbox).getSortedMessages(
sortTerms.getTerms());
for (int i = skip;
i < Math.min(skip + size, inbox.getMessageCount());
i++) {
resultList.add(messages[i]);
}
} else {
Message[] messages = inbox.getMessages();
for (int i = inbox.getMessageCount() - skip - 1;
i >= Math.max(inbox.getMessageCount() - skip - size - 1, 0);
i--) {
resultList.add(messages[i]);
}
}
Related
I like to ask How to read all received SMS message from Twilio Programmable SMS API (based on certain date).
I managed to figure out how to read all SMS message sent but can't find much resources around how to fetch all received SMS message, not sent.
Below is how you can read sent SMS message, not received message (sent After certain date)
Appreciate in advance.
TwilioClient.Init(accountSid, authToken);
var messages = MessageResource.Read(
dateSentAfter: new DateTime(2018, 12, 6, 0, 0, 0)
);
foreach (var record in messages)
{
Response.Write(record.DateCreated + ", From: " + record.From + ", To:" + record.To + "</br>" + " Body: " + record.Body + "</br></br>");
}
JavaScript use months 0 - 11 rather then 1 - 12.
So take this, using the date your currently have as the filter.
let a = new DateTime(2018, 12, 6, 0, 0, 0)
console.log(a)
Result: 2019-01-06T00:00:00.000Z
What you want is new DateTime(2018, 11, 6, 0, 0, 0)
Result: 2018-12-06T00:00:00.000Z
See if that fixes the issue.
The dateSent field is in both sent and received messages. You can set the To to your Twilio phone number to further reduce the dataset down to received SMS messages for that date.
I am trying to download public comments and replies from the FACEBOOK public post by page.
my code is working until 5 Feb'18, Now it is showing below error for the "Replies".
Error in data.frame(from_id = json$from$id, from_name = json$from$name, :
arguments imply differing number of rows: 0, 1
Called from: data.frame(from_id = json$from$id, from_name = json$from$name,
message = ifelse(!is.null(json$message), json$message, NA),
created_time = json$created_time, likes_count = json$like_count,
comments_count = json$comment_count, id = json$id, stringsAsFactors = F)
please refer below code I am using.
data_fun=function(II,JJ,page,my_oauth){
test <- list()
test.reply<- list()
for (i in II:length(page$id)){
test[[i]] <- getPost(post=page$id[i], token = my_oauth,n= 100000, comments = TRUE, likes = FALSE)
if (nrow(test[[i]][["comments"]]) > 0) {
write.csv(test[[i]], file = paste0(page$from_name[2],"_comments_", i, ".csv"), row.names = F)
for (j in JJ:length(test[[i]]$comments$id)){
test.reply[[j]] <-getCommentReplies(comment_id=test[[i]]$comments$id[j],token=my_oauth,n = 100000, replies = TRUE,likes = FALSE)
if (nrow(test.reply[[j]][["replies"]]) > 0) {
write.csv(test.reply[[j]], file = paste0(page$from_name[2],"_replies_",i,"_and_", j, ".csv"), row.names = F)
}}}
}
Sys.sleep(10)}
Thanks For Your support In advance.
I had the very same problem as Facebook changed the api rules at the end of January. If you update your package with 'devtools' from Pablo Barbera's github, it should work for you.
I have amended my code (a little) and it works fine now for replies to comments.There is one frustrating thing though, is that Facebook dont appear to allow one to extract the user name. I have a pool of data already so I am now using that to train and predict gender.
If you have any questions and want to make contact - drop me an email at 'robert.chestnutt2#mail.dcu.ie'
By the way - it may not be an issue for you, but I have had challenges in the past writing the Rfacebook output to a csv. Saving output as an .RData file maintains the form a lot better
I am using Firebase realtime database and overtime there is a lot of stale data in it and I have written a script to delete the stale content.
My Node structure looks something like this:
store
- {store_name}
- products
- {product_name}
- data
- {date} e.g. 01_Sep_2017
- some_event
Scale of the data
#Stores: ~110K
#Products: ~25
Context
I want to cleanup all the data which is like 30 months old. I tried the following approach :-
For each store, traverse all the products and for each date, delete the node
I ran ~30 threads/script instances and each thread is responsible for deleting a particular date of data in that month. The whole script is running for ~12 hours to delete a month data with above structure.
I have placed a limit/cap on the number of pending calls in each script and it is evident from logging that each script reaches the limit very quickly and speed of firing the delete call is much faster than speed of deletion So here firebase becomes a bottleneck.
Pretty evident that I am running purge script at client side and to gain performance script should be executed close to the data to save network round trip time.
Questions
Q1. How to delete firebase old nodes efficiently ?
Q2. Is there a way we can set a TTL on each node so that it cleans up automatically ?
Q3. I have confirmed from multiple nodes that data has been deleted from the nodes but firebase console is not showing decrease in data. I also tried to take backup of data and it still is showing some data which is not there when I checked the nodes manually. I want to know the reason behind this inconsistency.
Does firebase make soft deletions So when we take backups, data is actually there but is not visible via firebase sdk or firebase console because they can process soft deletes but backups don't ?
Q4. For the whole duration my script is running, I have a continuous rise in bandwidth section. With below script I am only firing delete calls and I am not reading any data still I see a consistency with database read. Have a look at this screenshot ?
Is this because of callbacks of deleted nodes ?
Code
var stores = [];
var storeIndex = 0;
var products = [];
var productIndex = -1;
const month = 'Oct';
const year = 2017;
if (process.argv.length < 3) {
console.log("Usage: node purge.js $beginDate $endDate i.e. node purge 1 2 | Exiting..");
process.exit();
}
var beginDate = process.argv[2];
var endDate = process.argv[3];
var numPendingCalls = 0;
const maxPendingCalls = 500;
/**
* Url Pattern: /store/{domain}/products/{product_name}/data/{date}
* date Pattern: 01_Jan_2017
*/
function deleteNode() {
var storeName = stores[storeIndex],
productName = products[productIndex],
date = (beginDate < 10 ? '0' + beginDate : beginDate) + '_' + month + '_' + year;
numPendingCalls++;
db.ref('store')
.child(storeName)
.child('products')
.child(productName)
.child('data')
.child(date)
.remove(function() {
numPendingCalls--;
});
}
function deleteData() {
productIndex++;
// When all products for a particular store are complete, start for the new store for given date
if (productIndex === products.length) {
if (storeIndex % 1000 === 0) {
console.log('Script: ' + beginDate, 'PendingCalls: ' + numPendingCalls, 'StoreIndex: ' + storeIndex, 'Store: ' + stores[storeIndex], 'Time: ' + (new Date()).toString());
}
productIndex = 0;
storeIndex++;
}
// When all stores have been completed, start deleting for next date
if (storeIndex === stores.length) {
console.log('Script: ' + beginDate, 'Successfully deleted data for date: ' + beginDate + '_' + month + '_' + year + '. Time: ' + (new Date()).toString());
beginDate++;
storeIndex = 0;
}
// When you have reached endDate, all data has been deleted call the original callback
if (beginDate > endDate) {
console.log('Script: ' + beginDate, 'Deletion script finished successfully at: ' + (new Date()).toString());
process.exit();
return;
}
deleteNode();
}
function init() {
console.log('Script: ' + beginDate, 'Deletion script started at: ' + (new Date()).toString());
getStoreNames(function() {
getProductNames(function() {
setInterval(function() {
if (numPendingCalls < maxPendingCalls) {
deleteData();
}
}, 0);
});
});
}
PS: This is not the exact structure I have but it is very similar to what we have (I have changed the node names and tried to make the example a realistic example)
Whether the deletes can be done more efficiently depends on how you now do them. Since you didn't share the minimal code that reproduces your current behavior it's hard to say how to improve it.
There is no support for a time-to-live property on documents. Typically developers do the clean-up in a administrative program/script that runs periodically. The more frequently you run the cleanup script, the less work it has to do, and thus the faster it will be.
Also see:
Delete firebase data older than 2 hours
How to delete firebase data after "n" days
Firebase actually deletes the data from disk when you tell it to. There is no way through the API to retrieve it, since it is really gone. But if you have a backup from a previous day, the data will of course still be there.
I'm new to AnyLogic and I am trying to create a custom network...but i don't get to succeed in this task :(
Agents have a parameter "AgeClass", that is an int from 0 to 14, according to their age.
Then I have a variable "network" that contains the mean number of links between age class.
What I want is every agent to create link with other agent according to the matrix.
I don't get how I can say to an agent "connect to another agent with AgeClass = 3"
I thought something like this (to put in the "on startup block" or in an event inside the agent type):
int i = AgeClass \\ this is the AgeClass of the agent who is executing the code
for( int j=0; j<network[i].length; j++ ) { \\ in this way I go through all the age classes
for ( int k=0; k<poisson(network[i] [j]); k++) { \\ for every j I get the mean # of link
connectTo(????);
}
}
Instead of ???? i want to say "connect to another agent with AgeClass = j" ...is there a way thorugh?
Thanks for the support!!!
Please use the function "filter()" to select all agents from the population with AgeClass = j. Then, you can get random of them to connect to the agent executing the code. The expression ???? may look like:
randomFrom(filter(main.people, p -> p.AgeClass == j))
Here is the description of the function "filter()":
http://help.anylogic.com/topic/com.xj.anylogic.help/html/agentbased/Subset.html
Everyone. I need to use union of every three sequence raster in database, so I use ILogicalOp.BooleanAnd. Weirdly I receive {"Exception from HRESULT: 0x80041098"} in third time of for loop.
Here is part of my code: error appear on temp=… In the following line when i==2.
ILogicalOp RMath;
for (int i = 0; i < inputRas.Length-2; i=i+1)
{
temp = RMath.BooleanAnd(inputRas[i], inputRas[i+1]);
rasOut = RMath.BooleanAnd(temp, inputRas[i + 2]);
}
Any comment will be appreciated.