Files
ayanova7/keys/Generator/ALRequests.cs
2018-06-29 19:47:36 +00:00

281 lines
10 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace GroundZero.KeyCodes
{
public partial class ALRequests : Form
{
private bool _xmlMode=true;
public ALRequests(bool XMLMode)
{
InitializeComponent();
_xmlMode=XMLMode;
}
private bool m_abortAtNextHeartbeat = false;
private Chilkat.EmailBundle bundle=null;
private void checkForRequestsToolStripMenuItem_Click(object sender, EventArgs e)
{
GetRequestsFromImapServer();
}
private void GetRequestsFromImapServer()
{
abortToolStripMenuItem.Visible = true;
// Any IMAP method call may be progress monitored and aborted.
// This example demonstrates how to do it.
Chilkat.Imap imap = new Chilkat.Imap();
bool success;
toolStripStatusLabel1.Text = "Unlock Chilkat...";
// Anything unlocks the component and begins a fully-functional 30-day trial.
success = imap.UnlockComponent("SAyanovaIMAPMAIL_Es9JHNMSlUlb");
if (success != true)
{
MessageBox.Show(imap.LastErrorText);
return;
}
// IMPORTANT: To enable events, make sure the EnableEvents property is set to true.
imap.EnableEvents = true;
// This example describes two event callbacks: AbortCheck and PercentDone:
imap.OnAbortCheck += new Chilkat.Imap.AbortCheckEventHandler(imap_OnAbortCheck);
imap.OnPercentDone += new Chilkat.Imap.PercentDoneEventHandler(imap_OnPercentDone);
// The AbortCheck event is fired periodically during any method call that communicates
// with the IMAP server. The rate of firing is controlled by the HeartbeatMs property.
// If set to 0 (the default), then no AbortCheck events are fired. Otherwise,
// the HeartbeatMs property is the number of milliseconds between AbortCheck events.
imap.HeartbeatMs = 100; // Set it to 100 milliseconds.
// NOTE: The PercentDone event is only fired for methods where it makes sense.
// For example, the AbortCheck event is fired during a Connect method call,
// but the PercentDone is not. (It's not really possible to know the percentage
// completion for a Connect -- the IMAP client simply waits for the server to accept
// the connection. However, when downloading 100 email headers, it's 50% done
// when 50 email headers have been downloaded, and that makes sense. When downloading
// a single email that is 100K in size, it's 50% done when 50K has been downloaded,
// again -- it makes sense. If the PercentDone event does not fire -- ask yourself
// if it even make sense.)
// Now that events have been enabled, and event handlers are set,
// the remainder of the code is identical to code that does not use events.
// Skip down to review the OnPercentDone and OnAbortCheck events.
// If you have an "Abort" button in your user-interface, you may wish
// to give it focus prior to calling progress-monitored methods:
menuStrip1.Focus();
// Connect to an IMAP server.
toolStripStatusLabel1.Text = "Connecting to mail.ayanova.com ...";
//Use SSL case 1973
imap.Ssl = true;
imap.Port = 993;
success = imap.Connect("mail.ayanova.com");
if (success != true)
{
MessageBox.Show(imap.LastErrorText);
return;
}
// Login
toolStripStatusLabel1.Text = "Logging in...";
success = imap.Login("support@ayanova.com", "RLdUP6758a6191H");
if (success != true)
{
MessageBox.Show(imap.LastErrorText);
return;
}
// Select an IMAP mailbox
toolStripStatusLabel1.Text = "Selecting Inbox...";
success = imap.SelectMailbox("Inbox");
if (success != true)
{
MessageBox.Show(imap.LastErrorText);
return;
}
Chilkat.MessageSet messageSet = null;
// We can choose to fetch UIDs or sequence numbers.
bool fetchUids;
fetchUids = true;
// Get the message IDs for all emails with "SSL" in the subject.
toolStripStatusLabel1.Text = "Searching ...";
//Tested oct 3 2011 this now works and only gathers new requests and now doesn't pick up people's replies to the keycode message
messageSet = imap.Search("UNANSWERED UNDELETED TEXT \"noreply@ayanova.com\" SUBJECT \"Request for 30 day temporary\"", fetchUids);
//messageSet = imap.Search("UNANSWERED SUBJECT \"Request for 30 day temporary\"", fetchUids);
//noreply@ayanova.com
// Fetch the email headers into an email bundle.
toolStripStatusLabel1.Text = "Fetching...";
bundle = imap.FetchBundle(messageSet);
if (bundle == null)
{
MessageBox.Show("Failed to fetch mail bundle!");
imap.SaveLastError("errorLog.xml");
return;
}
bundle.SortByDate(false);
// Loop over the bundle and display the FROM and SUBJECT of each.
grid.Rows.Clear();
int i;
for (i = 0; i <= bundle.MessageCount - 1; i++)
{
Chilkat.Email email = null;
email = bundle.GetEmail(i);
grid.Rows.Add(email.GetImapUid().ToString(), email.FromAddress + ": " + email.Subject + " - " + email.LocalDate.ToString());
}
// Disconnect from the IMAP server.
imap.Disconnect();
abortToolStripMenuItem.Visible = false;
toolStripStatusLabel1.Text = "Done...";
toolStripProgressBar1.Value = 0;
}
void imap_OnPercentDone(object sender, Chilkat.PercentDoneEventArgs args)
{
// Update the progress bar.
// args.PercentDone is an integer value that has a value from 0 to 100.
toolStripProgressBar1.Value = args.PercentDone;
}
// This is called periodically according to the HeartbeatMs
void imap_OnAbortCheck(object sender, Chilkat.AbortCheckEventArgs args)
{
// To abort any Chilkat IMAP method call, simply set the
// args.Abort property to true:
if (m_abortAtNextHeartbeat)
{
args.Abort = true;
m_abortAtNextHeartbeat = false;
abortToolStripMenuItem.Visible = false;
toolStripStatusLabel1.Text = "Abort!";
}
// Keep the user-interface responsive by allowing UI events to be processed:
Application.DoEvents();
}
private void abortToolStripMenuItem_Click(object sender, EventArgs e)
{
m_abortAtNextHeartbeat = true;
}
private void grid_CellClick(object sender, DataGridViewCellEventArgs e)
{
// Ignore clicks that are not on button cells.
if (e.RowIndex < 0 || e.ColumnIndex !=
grid.Columns["Process"].Index) return;
// Retrieve the task ID.
string msgID = grid[0, e.RowIndex].Value.ToString();
Chilkat.Email em=bundle.GetEmail(e.RowIndex);
if (em.Uidl==msgID)
MessageBox.Show("Error UIDL not equal to message ID from grid. Tell Johnny.");
else
{
string s = "";
if (!string.IsNullOrWhiteSpace(em.GetPlainTextBody()))
s = em.GetPlainTextBody();
else
s = em.Body;
ALResponse alr = new ALResponse(em,_xmlMode);
if(alr.ShowDialog()== System.Windows.Forms.DialogResult.Yes)
FlagImapEmailAnswered(em);
GetRequestsFromImapServer();
}
}
public static void FlagImapEmailAnswered(Chilkat.Email em)
{
Chilkat.Imap imap = new Chilkat.Imap();
bool success;
success = imap.UnlockComponent("SAyanovaIMAPMAIL_Es9JHNMSlUlb");
if (success != true)
{
MessageBox.Show(imap.LastErrorText);
return;
}
//Use SSL case 1973
imap.Ssl = true;
imap.Port = 993;
success = imap.Connect("mail.ayanova.com");
if (success != true)
{
MessageBox.Show(imap.LastErrorText);
return;
}
// Login
success = imap.Login("support@ayanova.com", "RLdUP6758a6191H");
if (success != true)
{
MessageBox.Show(imap.LastErrorText);
return;
}
// Select an IMAP mailbox
success = imap.SelectMailbox("Inbox");
if (success != true)
{
MessageBox.Show(imap.LastErrorText);
return;
}
success = imap.SetMailFlag(em, "Answered", 1);
if (success != true)
{
MessageBox.Show(imap.LastErrorText);
}
imap.Logout();
imap.Disconnect();
}
private void ALRequests_Load(object sender, EventArgs e)
{
GetRequestsFromImapServer();
}
//mailman.UnlockComponent("SAyanovaMAILQ_46WCmUg3lQ1i");
}
}