I am trying to do a mail app with Windows Forms C#. I only want to see the top 20 rows of my inbox.
Edit:
The code is working fine but only listing me 20 random emails in my inbox
I've tried this:
using (var client = new Pop3Client())
{
client.Connect("pop.gmail.com", 995, true);
client.Authenticate("mail", "passwrd");
for (int i = client.Count - 20; i < client.Count; i++)
{
var message = client.GetMessage(i);
Console.WriteLine("Subject: {0}", message.Subject);
txtBoxMails.AppendText("Subject: " + message.Subject + "\n");
}
client.Disconnect(true);
}
You can use GetMessages. It takes 2 parameters (int startIndex, int count). The index of the first message to get and how many messages.
An example without testing it.
var messages = client.GetMessages(0,20);
foreach (var item in messages)
{
Console.WriteLine(item.Subject);
}
you should use GetMessageCount instead of Count
var messageCount = client.GetMessageCount();
var lastMessageIndex = messageCount-20;
for (int i = messageCount; i > lastMessageIndex; i--)
{
//Do
}
Related
I'm trying to add only items that are new to the ObservableCollection, so as not to create duplicates. Everything is in an infinite loop so I can add the new ones. The problem is that I can't figure out the best way to prevent duplicates in the list. To prevent the program from throwing me an exception for comparing items in an empty sheet. So I add them first and if they don't meet the condition, I remove them.
But then it flashes on the screen, e.g. in a table, as new items are added. So what to do? Thanks for any suggestions
bool help = true;
do
{
using (var client = new ImapClient())
{
using (var cancel = new CancellationTokenSource())
{
client.Connect(emailParser.ServerName, emailParser.Port, emailParser.isSSLuse,
cancel.Token);
//client.AuthenticationMechanisms.Remove("XOAUTH");
client.Authenticate(emailParser.Username, emailParser.Password, cancel.Token);
var inbox = client.Inbox;
inbox.Open(FolderAccess.ReadOnly, cancel.Token);
Console.WriteLine("Total messages: {0}", inbox.Count);
Console.WriteLine("Recent messages: {0}", inbox.Unread);
for (int i = 0; i < inbox.Count; i++)
{
var message = inbox.GetMessage(i, cancel.Token);
alerts.Add(message); // I Think the problem is here
for (int j = 0; j < alerts.Count-1; j++)
{
if (alerts[j].MessageId.Equals(message.MessageId))
{
alerts.Remove(message);
}
}
}
Console.WriteLine(alerts.Count);
alerts.Count();
}
client.Disconnect(true);
}
} while (help != false);
How about you not add the item unless the condition is met, instead of adding and removing later? If you do, your for loop becomes
for (int i = 0; i < inbox.Count; i++)
{
var message = inbox.GetMessage(i, cancel.Token);
if (!alerts.Any(x => x.MessageId.Equals(message.MessageId))
{
alerts.Add(message);
}
}
Use LINQ's Any method for enumerables which is safe against empty collections
Now I'm making a method, after which the data is successfully sent from the telegram bot to the user. Now I have made this option. However, the problem is that all data is sent separately.
And if we assume we have 20 books in the matrix, we get 21 messages with customer data.
How can I make everything is sent in one message?
private void Form_DataAddAfter(ref SAPbouiCOM.BusinessObjectInfo pVal)
{
SAPbouiCOM.EditText oEdit_Customer = (SAPbouiCOM.EditText)this.GetItem("4").Specific;
SAPbouiCOM.EditText oEdit_Name = (SAPbouiCOM.EditText)this.GetItem("54").Specific;
SAPbouiCOM.EditText oEdit_PostingDate = (SAPbouiCOM.EditText)this.GetItem("10").Specific;
SAPbouiCOM.EditText oEdit_Total = (SAPbouiCOM.EditText)this.GetItem("29").Specific;
SendTextMessage(($"Return of the book!\n\nCustomer: {oEdit_Customer.Value}\nCustomer's name: {oEdit_Name.Value}\nReturn date: {oEdit_PostingDate.Value}\nTotal: {oEdit_Total.Value} "));
for (int j = 1; j < Matrix0.RowCount-1; j++)
{
SAPbouiCOM.EditText cell_Description = (SAPbouiCOM.EditText)Matrix0.Columns.Item("1").Cells.Item(j).Specific;
SAPbouiCOM.EditText cell_Quantity = (SAPbouiCOM.EditText)Matrix0.Columns.Item("U_inUseQuantity").Cells.Item(j).Specific;
SendTextMessage(($"Book: {cell_Description.Value}\nQuantity: {cell_Quantity.Value}"));
}
}
Not tested this code but should work.
Store your "messages" in a string variable add the strings you are currently sending to it. You can then send the string "sendText" after the loop
string sendText = "";
for (int j = 1; j < Matrix0.RowCount-1; j++)
{
SAPbouiCOM.EditText cell_Description = (SAPbouiCOM.EditText)Matrix0.Columns.Item("1").Cells.Item(j).Specific;
SAPbouiCOM.EditText cell_Quantity = (SAPbouiCOM.EditText)Matrix0.Columns.Item("U_inUseQuantity").Cells.Item(j).Specific;
sendText += $"Book: {cell_Description.Value}\nQuantity: {cell_Quantity.Value}\n";
}
SendTextMessage(sendText);
I know for a fact that I have only 54858 items in a table of mine that I am bringing over to a phone but for some reason, its managed to get passed this. Its got to 13600 so something must be wrong in my logic.
I am using realm.io to store my data on the phone locally. Also, how does one best dertimn the batch size because I won't no the amount of records all the time I cant just set /1000 because for the above that just gives me back 548 which is not correct to set the progress bar by.
int count = await restServices.GetStockTakeAllCountForWarehouse(warehouseId);
This returns the correct amount of records 54858
int batchsize = 1000;
int localCount = 0;
for (int i = 0; i < count; i += batchsize)
{
localCount += i;
lblCount.Text = $"Transefering Stock Count Sheet { localCount.ToString()}";
if (i >= count)
{
await DisplayAlert("Test", "Download of Stock Sheet Count complete", "OK");
return;
}
results = await restServices.GetStockTakeAllWithPagging(warehouseId, i, batchsize);
foreach (var items in results)
{ realm.Write(() =>
{
realm.Add(new RealmStockTakeItems { BinName = items.BinName, ItemCode = items.Code, Description = items.Name, BarCode = items.Barcode, UOM = items.StockUnitName, StocktakeCountShtItemID = items.StocktakeCountShtItemID, RecordedQuantityInStock =(int) items.RecordedQuantityInStock, ActualQuantityEntered = items.ActualQuantityEntered, ActualQuantityInStock = (int)items.ActualQuantityInStock });
});
}
}
So my program lets me send requests using WSDL the class below is provided by the WSDL:
CreateCustomerNoteRequest createCustomerNotesRequestInfo = new CreateCustomerNoteRequest();
Using this class I have to set the variables like this:
//FIRST WRITING NOTE TO OLD ACCOUNT TO SAY ITS BEEN COMPRIMISED AND SHOW NEW CUSTOMER NUMBER:
createCustomerNotesRequestInfo.UserName = username;
createCustomerNotesRequestInfo.Password = password;
createCustomerNotesRequestInfo.SystemToken = "sysToken";
createCustomerNotesRequestInfo.Note = new CustomerNote();
createCustomerNotesRequestInfo.Note.CustomerNumber = cloneCustomerNumber;
createCustomerNotesRequestInfo.Note.Category = new CustomerServiceWSDL.LookupItem();
createCustomerNotesRequestInfo.Note.Category.Code = "GEN";
createCustomerNotesRequestInfo.Note.Details = "Account Takeover – Fraud. Acc – " + customerNumberTextBox.Text + " closed as compromised and new account " + newCloneCustomerNumber + " created matching existing data";
And to finish off I use this to get my response:
createCustomerNotesResponse = soapClient.CreateCustomerNote(createCustomerNotesRequestInfo);
Everything works fine. What I want to do now is because I have multiple Notes I want to loop this process so depending on how many Note there are it would create that many instances.
I do successfully get all the Notes into a list like this using notecount which provides how many number of notes there are (Given by WSDL) so all is good so far:
try
{
for (int i = 0; i <= notesCount; i++)
{
customerNotesArrayList.Add(getCustomerNotesResponse.Notes.Items[i]);
//i++;
}
}
What I want to do: Now depending on the notes count I want to create that many of this:
CreateCustomerNoteRequest createCustomerNotesRequestInfo = new CreateCustomerNoteRequest();
I tried this:
for (int i=0; i<=notesCount;i++)
{
CreateCustomerNoteRequest a[i] = new CreateCustomerNoteRequest();
}
But its not as easy as that so how can I loop to make this happen?
So I want a1, a2, a3 where Ill then loop all the notes in later which shouldn't be a problem. But creating these in the first place is the problem.
[EDIT]
//Create Notes and copy over array contents...
CreateCustomerNoteRequest request = new CreateCustomerNoteRequest();
for (int i = 0; i <= notesCount; i++)
{
request.UserName = username;
request.Password = password;
request.SystemToken = systemToken;
request.Note = new CustomerNote();
request.Note.CustomerNumber = newCloneCustomerNumber;
request.Note.Category = new CustomerServiceWSDL.LookupItem();
request.Note.Category.Code = customerNotesArrayList[i].NoteCategory.Code.ToString();
request.Note.Details = customerNotesArrayList[i].NoteText;
var response = soapClient.CreateCustomerNote(request);
}
You're declaring the array inside the loop, which means it won't be available afterwards. Furthermore you need to declare the array size beforehand:
CreateCustomerNoteRequest[] a = new CreateCustomerNoteRequest[notesCount];
for (int i = 0; i < notesCount; i++)
{
a[i] = new CreateCustomerNoteRequest();
}
// now you can use the array outside the loop as well
Instead of an array you could choose to use a List<CreateCustomerNoteRequest>, which doesn't need a size declaration first.
Note that if you're planning to get the notes inside the same loop, you won't need the array at all:
for (int i = 0; i < notesCount; i++)
{
CreateCustomerNoteRequest request = new CreateCustomerNoteRequest();
var response = soapClient.CreateCustomerNote(request);
// todo process response
}
I'm trying to loop all the messages in specific inbox like using ActiveUp Mail C#:
Mailbox box = imap.AllMailboxes[0];
Fetch fetch = box.Fetch;
int messagesLeft = box.MessageCount; // return 31
int msgIndex = 0;
List<Email> list = new List<Email>();
for (int x = 1; x <= box.MessageCount; x++)
{
try
{
Message msg = fetch.MessageObject(x);
list.Add(new Email()
{
/// .....
});
}
catch { }
}
I'm getting an error for all the messages (except 1)..
Index and length must refer to a location within the string.
all of the messages (Except the 1 that working well) are from the same sender and has the same format (different content)
Imap4Client client = new Imap4Client();
client.Connect("server", 143);
client.Login("***", "***");
foreach (var box in client.AllMailboxes.OfType<Mailbox>())
{
for (int i = 1; i <= box.MessageCount; i++)
{
// a u wish
Header heade = box.Fetch.MessageObject(i);
}
}