IMAP S22.IMAP copy messages between servers - c#

I'm maiking a tool to migrate acoounts between servers.
I'm using S22.IMAP dll, but when I call to Client.CopyMessages(mailIDs, Client2.DefaultMailbox), it
creates the messages in the initial account (duplicate the messages and no copy to the other account server)..
Can anyone help me? thanks
Here is my code:
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;
using S22.Imap;
using System.Net.Mail;
namespace ImapPrueba1
{
public partial class Form1 : Form
{
private static IEnumerable<MailMessage> messages;
private static ImapClient imapClient = null;
private static IEnumerable<string> mailboxes, mailboxes2;
private static IEnumerable<uint> mailIDs;
private static MailMessage mailMessage;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
using (ImapClient Client = new ImapClient("correo.correo.com", 993,
"correo#correo.es", "xxxxxx", AuthMethod.Login, true))
{
ImapClient Client2 = new ImapClient("correonuevo.correonuevo.com", 993,
"correo#correo.es", "xxxxxx", AuthMethod.Login, true);
mailboxes = Client.ListMailboxes();
string mailbox, mailbox2;
for (int i = 0; i < mailboxes.Count(); i++) {
mailbox = mailboxes.ElementAt(i);
Client.DefaultMailbox = mailbox;
mailIDs = Client.Search(SearchCondition.All());
messages = Client.GetMessages(mailIDs);
//check the folder isn't in the destiny
mailboxes2 = Client2.ListMailboxes();
IEnumerable<string> items = mailboxes2.Where(p => p.Equals(mailbox));
int total = items.Count();
if (total == 0)
{
// set the folder in the destiny
Client2.CreateMailbox(mailbox);
}
Client2.DefaultMailbox = mailbox;
if (mailIDs.Count() > 0)
{
//copy to the destiny
Client.CopyMessages(mailIDs, Client2.DefaultMailbox);
}
}
label1.Text = "cambio";
}
}
}
}

Related

RTSP Streaming in Microsoft Dynamics Nav 2016 using Control add In

I am trying to do rtsp streaming in Nav 2016 using control add in using VLC player for dotnet. The control gets added on Nav page but i am not able to stream video from IP camera. The same code works fine on windows application but it does not work in Nav. Here is my sample code. please help me if i am doing anything wrong here.
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Dynamics.Framework.UI.Extensibility;
using Microsoft.Dynamics.Framework.UI.Extensibility.WinForms;
using System.Text.RegularExpressions;
using System.IO.Ports;
using WebEye.Controls.WinForms.StreamPlayerControl;
using Vlc.DotNet.Forms;
namespace WeighControl
{
[ControlAddInExport("CamControl")]
public class CamControl : WinFormsControlAddInBase
{
private VlcControl streamCam1;
private delegate void myDelegate(string str);
[ApplicationVisible]
public event MethodInvoker CamControlAddInReady;
[ApplicationVisible]
public void ShowCameraControl()
{
ShowCamera();
}
public CamControl()
{
}
private void ShowCamera()
{
try
{
streamCam1.Play(new Uri("rtsp://admin:admin#192.168.0.171/"));
}
catch(Exception ex)
{
}
}
protected override Control CreateControl()
{
streamCam1 = new VlcControl();
this.streamCam1.AutoSize = true;
this.streamCam1.BackColor = System.Drawing.Color.Black;
this.streamCam1.Spu = -1;
this.streamCam1.ForeColor = System.Drawing.Color.Black;
this.streamCam1.Location = new System.Drawing.Point(1, 416);
this.streamCam1.Margin = new System.Windows.Forms.Padding(2);
this.streamCam1.Name = "streamCam1";
string path = #"C:\Program Files\VideoLAN\VLC";
System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(path);
this.streamCam1.VlcLibDirectory = directoryInfo;
this.streamCam1.VlcMediaplayerOptions = null;
this.streamCam1.Size = new System.Drawing.Size(540, 226);
this.streamCam1.TabIndex = 2198;
streamCam1.HandleCreated += (sender, args) =>
{
if (CamControlAddInReady != null)
{
CamControlAddInReady();
}
};
return streamCam1;
}
}
}

Incorrect reading of an array

I am working in c-sharp .net and I am working on creating a login screen for my project. I have a text file with login info for all the users. My c-sharp scrip reads that file to a string then cuts it up into two lists, _usernames and _passwords. When the user types their login info and hits login the _usernames[0] and _passwords[0] account info are the only ones that work. What I want it to do is look through all the _usernames for the inputted one, if it finds it then check the _password[same index as _usernames] and if both are the same as what the user submitted then it will add "true" to the richTextBox.
Why is it not correctly reading from the array?
This is my users.txt:
admin,test|
andrew,yeet|
zana,happy|
This is my c-sharp script:
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BaseUserInterfase
{
public partial class Login : Form
{
string path = Directory.GetCurrentDirectory() + "\\data\\users.txt";
string data;
string[] _usernames = new string[10];
string[] _passwords = new string[10];
public Login()
{
InitializeComponent();
}
private void Login_Load(object sender, EventArgs e)
{
GetLoginData();
}
private void btnLogin_Click(object sender, EventArgs e)
{
rtbTemp.Text = "";
for(int i = 0; i < _usernames.Length; i++)
{
if(_usernames[i] == null)
{
break;
}
rtbTemp.AppendText("\n" + _usernames[i]);
rtbTemp.AppendText("\n" + tbUsername.Text.ToString());
rtbTemp.AppendText("\n" + _passwords[i]);
rtbTemp.AppendText("\n" + tbPassword.Text.ToString());
if (_usernames[i] == tbUsername.Text.ToString())
{
rtbTemp.AppendText("\nUsername true");
if (_passwords[i] == tbPassword.Text.ToString())
{
rtbTemp.AppendText("\nPassword true");
rtbTemp.AppendText("\ntrue");
return;
}
}
}
rtbTemp.AppendText("\nfalse");
}
public void GetLoginData()
{
using (StreamReader streamReader = new StreamReader(path, Encoding.UTF8))
{
data = streamReader.ReadToEnd();
}
List<string> _data = data.Split('|').ToList();
_data.RemoveAt(_data.Count - 1);
rtbTemp.AppendText("\n");
Array.Resize<string>(ref _usernames, _data.Count);
Array.Resize<string>(ref _passwords, _data.Count);
foreach (string _item in _data)
{
List<string> userdata = _item.Split(',').ToList();
string username = userdata[0].ToString();
string password = userdata[1].ToString();
Console.WriteLine(_item);
Console.WriteLine(username);
Console.WriteLine(password);
for(int i = 0; i < _data.Count; i++)
{
if(_usernames[i] == null)
{
_usernames[i] = username;
_passwords[i] = password;
break;
}
}
}
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
And this is an image of the login screen:
1
Your file contains carriage return characters. Remove them before you split its content
data = streamReader.ReadToEnd().Replace("\r\n", "");

Access to file denied in C# .NET 3.1 forms

Hello I was writing a basic text editor in C# on visual studio windows form using the .NET framework 3.1 long term support version everything worked fine until I wrote the save file script
Here's the code for "Form1.cs" which is where the open and save file functions reside
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Security.Principal;
namespace Text_Editor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string locsave;
private void openbtn_Click(object sender, EventArgs e)
{
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
if (principal.IsInRole(WindowsBuiltInRole.Administrator) != true)
{
MessageBox.Show("Run as Admin");
System.Windows.Forms.Application.ExitThread();
}
else
{
OpenFileDialog openfile = new OpenFileDialog();
if (openfile.ShowDialog() == DialogResult.OK)
{
var locationArray = openfile.FileName;
string location = "";
locsave = locationArray;
foreach (char peice in locationArray)
{
location = location + peice;
}
var contentArray = File.ReadAllText(location);
string content = "";
label4.Text = location;
foreach (char peice in contentArray)
{
content = content + peice;
}
richTextBox1.Text = content;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
Console.WriteLine("Test");
}
private void savebtn_Click(object sender, EventArgs e)
{
if (#label4.Text == "")
{
MessageBox.Show("Open a text file first");
}
else
{
StreamWriter outputfile = new StreamWriter(locsave);
outputfile.Write(richTextBox1.Text); //this is where the error occures and it throws the error of access denyed
outputfile.Close();
}
}
}
}
Does anyone have a suggestion about what to do I looked around on google for a solution but it seemed most did not work and some others I did not understand.

Send Print job from PuTTY to Zebra ZXP 3 SDK (non.zpl printer)

What I have is a medical record database that is accessed via PuTTY (SSH client). The cards themselves will only have Client name, record number in a barcode format (still determining the barcode type to be used), and client registration date.
1) We can get the data output as .zpl for Zebra Barcode label printers or formats compatible with laser printers like HP or Brother in a RAW format.
2) What output WILL the ZXP 3 SDK accept?
3) Can the SDK be set up to wait for and accept data coming at it using a command line from something like RedMon?
The cards themselves will only have the printed data, no mag stripe, smart chips, laminates or anything like that.
Mahalo in advance.
I would not recommend using either RedMon nor the SDK, as neither are required for what you are trying to do, and they both are time-vampires. Instead, I would write a small Windows Forms application which listens on a TCP port to receive the print job and send it to the standard printer which uses the Zebra driver.
Have the MUMPS application send an XML document via the Remote Print support in VT100. The example I have been using is below:
^[[5i
<patient>
<name first="John" last="Smith" />
<mrn>A04390503</mrn>
<dob>1991-03-12</dob>
</patient>
^[[4i
Configure a printer on the windows client to redirect to TCP/IP:
Add Printer
Local printer
Create a new port
Standard TCP/IP Port
Hostname: 127.0.0.1
Port name: CardFormatter
Uncheck "Query the printer and automatically select the driver to use"
Device type: Custom
Protocol: Raw
Port: 9101
Driver: Generic / Text Only
Start the application at logon, and print from the server. The MUMPS application will send back the XML, which Putty prints to the Text printer, which gets sent to the C# application on localhost. The C# application interprets the XML and prints to the actual printer via the Zebra driver or SDK.
Note: This only assumes one interactive session per workstation. If you are using fast-user-switching or terminal services, further care must be taken to ensure things work properly.
Example App:
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PassThroughPrinterTest
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new TrayApplicationContext());
}
}
}
TrayApplicationContext.cs
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PassThroughPrinterTest
{
class TrayApplicationContext : ApplicationContext
{
private NotifyIcon trayIcon;
private PrintListener listener;
private PrintHandler handler;
public TrayApplicationContext()
{
this.trayIcon = new NotifyIcon()
{
Text = "Card Formatter",
Icon = Properties.Resources.AppIcon,
ContextMenu = new ContextMenu()
{
MenuItems =
{
new MenuItem("Print Options...", miPrintOptions_Click),
new MenuItem("Exit", miExit_Click)
}
},
Visible = true
};
this.handler = new PrintHandler();
this.listener = new PrintListener(9101);
this.listener.PrintDataReceived += this.handler.HandlePrintData;
}
private void miPrintOptions_Click(object sender, EventArgs args)
{
// TODO: add configuration and options to avoid having to hard code
// the printer name in PrintHandler.cs
MessageBox.Show("Options");
}
private void miExit_Click(object sender, EventArgs args)
{
Application.Exit();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
trayIcon.Dispose();
}
}
}
}
PrintHandler.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
namespace PassThroughPrinterTest
{
partial class PrintHandler : Form
{
public PrintHandler()
{
InitializeComponent();
}
public void HandlePrintData(object sender, PrintDataReceivedEventArgs args)
{
if (this.InvokeRequired)
{
this.Invoke(new EventHandler<PrintDataReceivedEventArgs>(HandlePrintData), sender, args);
return;
}
this.Show();
var sXml = Encoding.UTF8.GetString(args.PrintData);
this.PrintCard(XDocument.Parse(sXml));
this.Hide();
}
private void PrintCard(XDocument xDocument)
{
var nameElement = xDocument.Root.Element("name");
var lastName = nameElement.Attribute("last").Value;
var firstName = nameElement.Attribute("first").Value;
var mrn = xDocument.Root.Element("mrn").Value;
var printDoc = new PrintDocument()
{
PrinterSettings = new PrinterSettings()
{
PrinterName = "Adobe PDF"
},
DocumentName = "Patient ID Card"
};
var cardPaperSize = new PaperSize("Card", 337, 213) { RawKind = (int)PaperKind.Custom };
printDoc.DefaultPageSettings.PaperSize = cardPaperSize;
printDoc.PrinterSettings.DefaultPageSettings.PaperSize = cardPaperSize;
printDoc.PrintPage += (s, e) =>
{
var gfx = e.Graphics;
// print the text information
var fArial12 = new Font("Arial", 12);
gfx.DrawString(lastName, fArial12, Brushes.Black, new RectangleF(25, 25, 200, 75));
gfx.DrawString(firstName, fArial12, Brushes.Black, new RectangleF(25, 100, 200, 75));
// add a code39 barcode using a barcode font
// http://www.idautomation.com/free-barcode-products/code39-font/
// var fCode39 = new Font("IDAutomationHC39M", 12);
// gfx.DrawString("(" + mrn + ")", fArial12, Brushes.Black, new RectangleF(25, 200, 200, 75));
// or by using a barcode library
// https://barcoderender.codeplex.com/
// var barcode = BarcodeDrawFactory.Code128WithChecksum.Draw(mrn, 20, 2);
// gfx.DrawImage(barcode, 50, 200);
e.HasMorePages = false;
};
printDoc.Print();
}
}
}
PrintListener.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace PassThroughPrinterTest
{
sealed class PrintListener : IDisposable
{
private TcpListener listener;
public event EventHandler<PrintDataReceivedEventArgs> PrintDataReceived;
public PrintListener(int port)
{
this.listener = new TcpListener(IPAddress.Loopback, port);
this.listener.Start();
this.listener.BeginAcceptTcpClient(listener_AcceptClient, null);
}
public void Dispose()
{
this.listener.Stop();
}
private void listener_AcceptClient(IAsyncResult iar)
{
TcpClient client = null;
bool isStopped = false;
try
{
client = this.listener.EndAcceptTcpClient(iar);
}
catch (ObjectDisposedException)
{
// this will occur in graceful shutdown
isStopped = true;
return;
}
finally
{
if (!isStopped)
{
this.listener.BeginAcceptTcpClient(listener_AcceptClient, null);
}
}
Debug.Assert(client != null);
try
{
byte[] printData;
using (var clientStream = client.GetStream())
using (var buffer = new MemoryStream())
{
clientStream.CopyTo(buffer);
printData = buffer.ToArray();
}
OnPrintDataReceived(printData);
}
catch
{
// TODO: add logging and error handling for network issues or processing issues
throw;
}
finally
{
client.Close();
}
}
private void OnPrintDataReceived(byte[] printData)
{
var handler = PrintDataReceived;
if (handler != null)
{
handler(this, new PrintDataReceivedEventArgs(printData));
}
}
}
}
TrayApplicationContext.cs
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PassThroughPrinterTest
{
class TrayApplicationContext : ApplicationContext
{
private NotifyIcon trayIcon;
private PrintListener listener;
private PrintHandler handler;
public TrayApplicationContext()
{
this.trayIcon = new NotifyIcon()
{
Text = "Card Formatter",
Icon = Properties.Resources.AppIcon,
ContextMenu = new ContextMenu()
{
MenuItems =
{
new MenuItem("Print Options...", miPrintOptions_Click),
new MenuItem("Exit", miExit_Click)
}
},
Visible = true
};
this.handler = new PrintHandler();
this.listener = new PrintListener(9101);
this.listener.PrintDataReceived += this.handler.HandlePrintData;
}
private void miPrintOptions_Click(object sender, EventArgs args)
{
// TODO: add configuration and options to avoid having to hard code
// the printer name in PrintHandler.cs
MessageBox.Show("Options");
}
private void miExit_Click(object sender, EventArgs args)
{
Application.Exit();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
listener.Dispose();
trayIcon.Dispose();
}
}
}
}
PrintDataReceivedEventArgs.cs
using System;
namespace PassThroughPrinterTest
{
class PrintDataReceivedEventArgs : EventArgs
{
public byte[] PrintData { get; set; }
public PrintDataReceivedEventArgs(byte[] data)
{
if (data == null)
throw new ArgumentNullException("data");
this.PrintData = data;
}
}
}

IMAP searchParse exception?

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;
using System.Web;
using ActiveUp.Net.Mail;
using ActiveUp.Net.Imap4;
namespace imapClient
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Imap4Client client = new Imap4Client();
client.ConnectSsl("imap.gmail.com", 993);
MessageBox.Show("connected!");
client.Login("soham.elf", "********");
MessageBox.Show("signed in!");
Mailbox mail = client.SelectMailbox("INBOX");
//exception thrown here
MessageCollection msgs = mail.SearchParse("ALL");
textBox1.Text = msgs.Count.ToString();
}
}
}
Expection:"Index and length must refer to a location within the string.
Parameter name: length"
I am trying to test the IMAP client; I'm just starting with it. I am using mailsystem.NET. What's wrong with my code?
Try use Phrases like that document: http://www.limilabs.com/blog/imap-search-requires-parentheses
private void SearchFromTest()
{
try
{
var _selectedMailBox = "INBOX";
var _searchWithEmailFrom = "email#domain.com";
using (var _clientImap4 = new Imap4Client())
{
_clientImap4.ConnectSsl(_imapServerAddress, _imapPort);
//_clientImap4.Connect(_mailServer.address, _mailServer.port);
_clientImap4.Login(_imapLogin, _imapPassword); // Efetua login e carrega as MailBox da conta.
//_clientImap4.LoginFast(_imapLogin, _imapPassword); // Efetua login e não carrega as MailBox da conta.
var _mailBox = _clientImap4.SelectMailbox(_selectedMailBox);
// A0001 SEARCH CHARSET utf-8 BODY "somestring" OR TO "someone#me.com" FROM "someone#me.com"
var searchPhrase = "CHARSET utf-8 FROM \"" + _searchWithEmailFrom + "\"";
foreach (var messageId in _mailBox.Search(searchPhrase).AsEnumerable())
{
var message = _mailBox.Fetch.Message(messageId);
var _imapMessage = Parser.ParseMessage(message);
}
_clientImap4.Disconnect();
}
Assert.IsTrue(true);
}
catch (Exception e)
{
Assert.Fail("Don't work.", e);
}
}

Categories

Resources