/// <summary>
        /// Parse the bytes from Fiddler and append the parsed
        /// string to the WebBrowser document window
        /// </summary>
        /// <param name="bytesFromFiddler">byte[] from Fiddler</param>
        public void Parse(byte[] bytesFromFiddler)
        {
            if (bytesFromFiddler.Length == 0)
            {
                return;
            }

            InspectorUtilities.SetFiddlerStatus("Parsing payload...");

            // Try to only decode valid EAS requests/responses
            try
            {
                ASCommandResponse commandResponse = new ASCommandResponse(bytesFromFiddler);

                if (!string.IsNullOrEmpty(commandResponse.XMLString) && commandResponse.XMLString.Contains(@"<?xml"))
                {
                    this.oEasViewControl.SetRaw(commandResponse.XMLString);

                    XmlDocument doc       = commandResponse.XmlDoc;
                    string      outputDoc = InspectorUtilities.TransformXml(doc);
                    this.oEasViewControl.AppendLine(outputDoc);
                }

                commandResponse = null;
            }
            catch (Exception ex)
            {
                oEasViewControl.Append(InspectorUtilities.FriendlyException(@"Error in decoding EAS body.", ex.ToString()));
            }

            InspectorUtilities.SetFiddlerStatus(this.session.fullUrl);
        }
예제 #2
0
        private void btnLoadFile_Click(object sender, EventArgs e)
        {
            txtEncoded.Text = string.Empty;
            txtEncoded.Update();
            txtDecoded.Text = string.Empty;
            txtDecoded.Update();


            // PickLoadFromFile
            string sFileName = txtFile.Text.Trim();

            try
            {
                if (System.IO.File.Exists(sFileName) == false)
                {
                    MessageBox.Show("The specified file does not exist.", "File does not exist.");
                }
                else
                {
                    //PickLoadFromFile

                    wbxmlBytes = System.IO.File.ReadAllBytes(sFileName);
                    ASCommandResponse commandResponse = new ASCommandResponse(wbxmlBytes);

                    txtEncoded.Text = MyHelpers.StringHelper.HexDumpFromByteArray(wbxmlBytes);

                    txtDecoded.Text = commandResponse.XMLString;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException.ToString(), "Error loading file");
            }
            //wbxmlBytes
        }
예제 #3
0
        private void ConvertFromHexString(string sHex)
        {
            StringBuilder sb               = null;
            bool          bContinue        = true;
            string        sHexStingErrors  = string.Empty;
            string        sToDump          = string.Empty;
            string        sEASDecoded      = string.Empty;
            string        StringByteErrors = string.Empty;
            StringBuilder oPureHexStream   = new StringBuilder();

            try
            {
                // Convert to two byte hex values with space delimiter.
                string sHexStrings = sHex; //.Trim();
                sb = new StringBuilder();
                int iCount    = 0;
                int iPosition = 0;
                foreach (char a in sHexStrings)
                {
                    iPosition++;

                    if ((a >= 'a' && a <= 'f') ||
                        (a >= 'A' && a <= 'F') ||
                        (a >= '0' && a <= '9'))
                    {
                        sb.Append(a);
                        iCount += 1;
                        if (iCount == 2)
                        {
                            sb.Append(' ');
                            iCount = 0;
                        }
                    }
                    else
                    {
                        sb.Append(a);
                        sHexStingErrors += string.Format("A non-hex character found at position {0}.  Character'{1}' was found. \r\n", iPosition, a);
                        sHexStingErrors += string.Format("Below is what was converted so far: \r\n{0}\r\n", PurgeWhiteSpace(sb.ToString()));
                        iCount          += 1;
                        bContinue        = false;

                        break;
                    }
                }


                if (bContinue == true)
                {
                    sHexStrings = sb.ToString().TrimEnd();


                    string[]      hexValuesSplit = sHexStrings.Split(' ');
                    byte[]        oBytes         = new byte[hexValuesSplit.Length];
                    int           iCountBytes    = 0;
                    StringBuilder oSbConvertDiag = new StringBuilder();

                    foreach (String hex in hexValuesSplit)
                    {
                        oBytes[iCountBytes] = Convert.ToByte(hex, 16);

                        oSbConvertDiag.Append(hex);

                        if (hex.Length != 2)
                        {
                            StringByteErrors += string.Format("Byte pair '{0}' does not have two byte values at pair poisition {1}.\r\n\r\n", hex, iCountBytes);
                            StringByteErrors += string.Format("Below is what has been processed so far: \r\n{0}", oSbConvertDiag.ToString());

                            bContinue = false;
                            break;
                        }
                        //else
                        //{
                        //    oBytes[iCountBytes] = Convert.ToByte(hex, 16);
                        //}

                        iCountBytes++;
                    }



                    //if (sHexStingErrors.Length != 0)
                    //{
                    //    sToDump = "Content up to bad byte pair: \r\n" + MyHelpers.StringHelper.HexDumpFromByteArray(oBytes); // Dump what we have
                    //    sToDump += "\r\n\r\n" + sHexStingErrors;
                    //}

                    if (bContinue == true)
                    {
                        sToDump = MyHelpers.StringHelper.HexDumpFromByteArray(oBytes);
                        ASCommandResponse commandResponse = new ASCommandResponse(oBytes);
                        sEASDecoded = commandResponse.XMLString;
                    }
                }

                if (sHexStingErrors.Length != 0)
                {
                    txtTo.Text += "\r\nError parsing values: " + sHexStingErrors;
                }

                if (StringByteErrors.Length != 0)
                {
                    txtTo.Text += "\r\n\r\n" + StringByteErrors;
                }


                sEASDecoded = CheckForResultingBadCharacters(sEASDecoded);

                txtToDump.Text     = sToDump;
                txtEASDecoded.Text = sEASDecoded;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }
예제 #4
0
        public bool SetConnection(ref string sessionKey, ref string kom)
        {
            try
            {
                ASOptionsRequest optionsRequest = new ASOptionsRequest();
                optionsRequest.Server      = server;
                optionsRequest.UseSSL      = true;
                optionsRequest.Credentials = cred;

                bool isWipeRequested = false;

                // Send the request

                ASOptionsResponse optionsResponse = optionsRequest.GetOptions();

                //check dev status
                string           setXml  = SetSettingsObjectAsXml();
                ASCommandRequest request = CreateCommandRequest("Settings", cred, devID, devType, protVer, server, username, setXml);

                ASCommandResponse response = request.GetResponse();

                // create xml provision content

                string provXml = SetProvisionObjectAsXml();
                request = CreateCommandRequest("Provision", cred, devID, devType, protVer, server, username, provXml);

                response = request.GetResponse();
                EAS.generated.ProvisionResponseNamespace.Provision provResponse = GetProvisionObjectFromXML(response.XmlString);
                sessionKey = string.Empty;

                if (provResponse != null && provResponse.Policies != null && provResponse.Policies.Policy != null)
                {
                    sessionKey = provResponse.Policies.Policy.PolicyKey;
                    if (!string.IsNullOrEmpty(provResponse.RemoteWipe))
                    {
                        Directory.Delete(mailDir, true);
                        Properties.Settings.Default.Password = string.Empty;
                        Properties.Settings.Default.Username = string.Empty;
                        Properties.Settings.Default.SyncKey  = string.Empty;
                        Properties.Settings.Default.Save();
                        isWipeRequested = true;
                    }
                }

                string provAckXml = SetProvisionObjectACKAsXml(sessionKey, isWipeRequested);
                request  = CreateCommandRequest("Provision", cred, devID, devType, protVer, server, username, provXml);
                response = request.GetResponse();
                EAS.generated.ProvisionResponseNamespace.Provision provResponseAck = GetProvisionObjectFromXML(response.XmlString);
                if (provResponseAck != null && provResponseAck.Policies != null && provResponseAck.Policies.Policy != null)
                {
                    sessionKey = provResponseAck.Policies.Policy.PolicyKey;
                }
                if (!isWipeRequested)
                {
                    return(true);
                }
                else
                {
                    kom = _rm.GetString("strWipeReq");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                kom = _rm.GetString("lblTotalGenericErrorRes") + " " + ex.Message;
                return(false);
            }
        }
예제 #5
0
        private void WriteEmailsToDirectory(List <string> lstEmailsSid, string folderToSync, uint policyKey)
        {
            ASCommandResponse commandResponse = null;
            int fileNo = 1;

            foreach (string sid in lstEmailsSid)
            {
                string nazwaPlikuZKatalogiem = mailDir + "\\" + sid.Replace(":", "");
                if (!File.Exists(nazwaPlikuZKatalogiem + ".eml"))
                {
                    string        fetchXml   = SetFetchDataObjectAsXml(folderToSync, sid, true);
                    StringBuilder xmlBuilder = new StringBuilder();
                    xmlBuilder.Append(fetchXml);

                    ASCommandRequest commandRequest = CreateCommandRequest("ItemOperations", cred, devID, devType, protVer, server, username, xmlBuilder.ToString(), policyKey);

                    // Send the request
                    commandResponse = commandRequest.GetResponse();

                    EAS.generated.ItemOperationsResponseNamespace.ItemOperations emailFetched = GetFetchedMail(commandResponse.XmlString);
                    if (emailFetched != null && emailFetched.Response != null && emailFetched.Response.Fetch != null && emailFetched.Response.Fetch.Count() > 0)
                    {
                        //WYCHWYC BODY
                        EAS.generated.ItemOperationsResponseNamespace.Body b = null;
                        List <EAS.generated.ItemOperationsResponseNamespace.ItemsChoiceType3> lst = emailFetched.Response.Fetch[0].Properties.ItemsElementName.ToList();
                        int index = lst.FindIndex(q => q == EAS.generated.ItemOperationsResponseNamespace.ItemsChoiceType3.Body);
                        if (index > 0)
                        {
                            if (emailFetched.Response.Fetch[0].Properties.ItemsElementName[index] == EAS.generated.ItemOperationsResponseNamespace.ItemsChoiceType3.Body)
                            {
                                b = (EAS.generated.ItemOperationsResponseNamespace.Body)emailFetched.Response.Fetch[0].Properties.Items[index];
                            }
                        }

                        if (b != null)
                        {
                            string s = b.Data;

                            MemoryStream ms = new MemoryStream();
                            StreamWriter sw = new StreamWriter(ms);
                            sw.Write(s);
                            sw.Flush();
                            ms.Seek(0, SeekOrigin.Begin);

                            MimeKit.MimeMessage mm = MimeKit.MimeMessage.Load(ms);
                            sw.Close();
                            ms.Close();


                            if (!string.IsNullOrEmpty(mm.HtmlBody))
                            {
                                string body     = mm.HtmlBody;
                                string sContent = BitConverter.ToString(Encoding.UTF8.GetBytes(body));


                                int idx = 0;
                                do
                                {
                                    idx = sContent.IndexOf("C3", idx);
                                    if (idx != -1)
                                    {
                                        string podciag = sContent.Substring(idx, sContent.Length - idx);

                                        if (podciag.StartsWith("C3-83") || podciag.StartsWith("C3-84") || podciag.StartsWith("C3-85") || podciag.StartsWith("C3-82") ||
                                            podciag.StartsWith("C3-A2"))    //WYCINA CUDZYSŁÓW i apostrof w pewnych dziwnych przypadkach..
                                        {
                                            if (podciag.Length > 10)
                                            {
                                                //string subPodciag = podciag.Substring(9, 2);
                                                //if ( subPodciag != "AD" || subPodciag != "AA" || subPodciag != "AC" || subPodciag != "AE" || subPodciag != "AF"
                                                //|| subPodciag != "A1" || subPodciag != "A2" || subPodciag != "A0" || subPodciag != "A3" || subPodciag != "A4" || subPodciag != "A5" || subPodciag != "A6" || subPodciag != "A7" || subPodciag != "A8" || subPodciag != "A9"
                                                //|| subPodciag != "B0" || subPodciag != "B1" || subPodciag != "B2" || subPodciag != "B3" || subPodciag != "B4" || subPodciag != "B5" || subPodciag != "B6" || subPodciag != "B7" || subPodciag != "B8" || subPodciag != "B9" || subPodciag != "B0"
                                                //|| subPodciag != "BA" || subPodciag != "BB" || subPodciag != "BC" || subPodciag != "BD" || subPodciag != "BE" || subPodciag != "BF")
                                                {
                                                    sContent = sContent.Remove(idx + 1, 3);
                                                    sContent = sContent.Remove(idx + 3, 3);
                                                }
                                            }
                                        }
                                        idx++;
                                    }
                                } while (idx != -1);


                                string[] sArr = sContent.Split('-');

                                byte[] bNew = new byte[sArr.Length];
                                for (int i = 0; i < sArr.Length; i++)
                                {
                                    byte byt = Convert.ToByte(sContent.Substring(3 * i, 2), 16);

                                    bNew[i] = byt;
                                }

                                string enc = Encoding.UTF8.GetString(bNew);

                                s = s.Replace(body, enc);

                                //recreate object
                                ms = new MemoryStream();
                                sw = new StreamWriter(ms);
                                sw.Write(s);
                                sw.Flush();
                                ms.Seek(0, SeekOrigin.Begin);
                                mm = MimeKit.MimeMessage.Load(ms);
                                sw.Close();
                                ms.Close();
                            }

                            mm.WriteTo(nazwaPlikuZKatalogiem + ".eml");
                            OnNewFilesNumberEvent(string.Format("{0} {1}", fileNo, _rm.GetString("strEmailsDownloaded")));
                            fileNo++;
                        }
                    }
                    else
                    {
                        MessageBox.Show(_rm.GetString("errSerialization"));
                    }
                }
            }
        }
예제 #6
0
        public bool SetConversation(string sessionKey, string syncKey, ref string kom)
        {
            try
            {
                string            folderToSync    = string.Empty;
                string            days            = string.Empty;
                uint              policyKey       = uint.Parse(sessionKey);
                StringBuilder     xmlBuilder      = null;
                ASCommandRequest  commandRequest  = null;
                ASCommandResponse commandResponse = null;
                string            postfixFolder   = string.Empty;
                if (syncKey == "0")
                {
                    xmlBuilder = new StringBuilder();
                    if (Directory.Exists(mailDir))
                    {
                        xmlBuilder.Append(SetFolderSyncObjectAsXml("0"));
                    }

                    commandRequest = CreateCommandRequest("FolderSync", cred, devID, devType, protVer, server, username, xmlBuilder.ToString(), policyKey);

                    // Send the request
                    commandResponse = commandRequest.GetResponse();

                    Console.WriteLine("XML Response: {0}", commandResponse.XmlString);
                    EAS.generated.FolderResponseNamespace.FolderSync fsFromEAS = GetFolderSyncObjectFromXML(commandResponse.XmlString);

                    if (fsFromEAS != null && fsFromEAS.Status == "1" && fsFromEAS.Changes != null && fsFromEAS.Changes.Add != null)
                    {
                        List <List <string> > lstDirsToChoose  = new List <List <string> >();
                        List <string>         lstDirsToDisplay = new List <string>();
                        foreach (EAS.generated.FolderResponseNamespace.FolderSyncChangesAdd fsca in fsFromEAS.Changes.Add)
                        {
                            if (fsca.Type == "5" || fsca.Type == "2")
                            {
                                lstDirsToChoose.Add(new List <string> {
                                    fsca.ServerId, fsca.DisplayName
                                });
                                lstDirsToDisplay.Add(fsca.DisplayName);
                            }
                        }
                        FolderDecision fd = new FolderDecision(lstDirsToDisplay, true);
                        fd.SelectedFolder = lstDirsToChoose.Where(q => q[0] == "4").FirstOrDefault()[1];
                        fd.ShowDialog();

                        if (!Directory.Exists(mailDir + "\\" + fd.SelectedFolder.Replace(" ", "")))
                        {
                            Directory.CreateDirectory(mailDir + "\\" + fd.SelectedFolder.Replace(" ", ""));
                        }
                        mailDir      = mailDir + "\\" + fd.SelectedFolder.Replace(" ", "");
                        folderToSync = lstDirsToChoose.Where(q => q[1] == fd.SelectedFolder).FirstOrDefault()[0];
                        days         = fd.SelectedTime;
                    }

                    //sync 1

                    xmlBuilder = new StringBuilder();

                    xmlBuilder.Append(SetSyncObjectAsXml(syncKey, folderToSync, days));

                    XmlDocument xDoc = new XmlDocument();
                    xDoc.PreserveWhitespace = true;
                    xDoc.LoadXml(xmlBuilder.ToString());

                    commandRequest.XmlString = xDoc.InnerXml;

                    // Send the request
                    commandRequest  = CreateCommandRequest("Sync", cred, devID, devType, protVer, server, username, xmlBuilder.ToString(), policyKey);
                    commandResponse = commandRequest.GetResponse();

                    EAS.generated.SyncResponseNamespace.Sync syncResponse = GetSyncObjectFromXML(commandResponse.XmlString);
                    if (syncResponse != null)
                    {
                        if (syncResponse.Item is EAS.generated.SyncResponseNamespace.SyncCollections)
                        {
                            EAS.generated.SyncResponseNamespace.SyncCollections sc = (EAS.generated.SyncResponseNamespace.SyncCollections)syncResponse.Item;

                            if (sc.Collection != null)
                            {
                                //WYCHWYC INBOX
                                foreach (EAS.generated.SyncResponseNamespace.SyncCollectionsCollection scc in sc.Collection)
                                {
                                    List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7> lst = new List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7>(scc.ItemsElementName);
                                    int index = lst.FindIndex(q => q == EAS.generated.SyncResponseNamespace.ItemsChoiceType7.CollectionId);
                                    if (index > 0)
                                    {
                                        if (scc.Items[index].ToString() == folderToSync)
                                        {
                                            List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7> lstSync = new List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7>(scc.ItemsElementName);
                                            int indexSync = lst.FindIndex(q => q == EAS.generated.SyncResponseNamespace.ItemsChoiceType7.SyncKey);

                                            syncKey = scc.Items[indexSync].ToString();
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                List <string> lstEmailsToFetch = new List <string>();
                bool          continuingLoop   = true;
                do
                {
                    //sync2
                    xmlBuilder = new StringBuilder();
                    xmlBuilder.Append(SetSyncObjectAsXml(syncKey, folderToSync, days));

                    // Send the request
                    commandRequest           = CreateCommandRequest("Sync", cred, devID, devType, protVer, server, username, xmlBuilder.ToString(), policyKey);
                    commandRequest.XmlString = xmlBuilder.ToString();
                    commandResponse          = commandRequest.GetResponse();

                    EAS.generated.SyncResponseNamespace.Sync syncResponse2 = GetSyncObjectFromXML(commandResponse.XmlString);

                    if (syncResponse2 != null)
                    {
                        if (syncResponse2.Item is EAS.generated.SyncResponseNamespace.SyncCollections)
                        {
                            EAS.generated.SyncResponseNamespace.SyncCollections sc = (EAS.generated.SyncResponseNamespace.SyncCollections)syncResponse2.Item;

                            if (sc.Collection != null)
                            {
                                EAS.generated.SyncResponseNamespace.SyncCollectionsCollection[] scc = sc.Collection;
                                foreach (EAS.generated.SyncResponseNamespace.SyncCollectionsCollection sccItem in scc)
                                {
                                    List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7> lst = new List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7>(sccItem.ItemsElementName);
                                    int index = lst.FindIndex(q => q == EAS.generated.SyncResponseNamespace.ItemsChoiceType7.CollectionId);
                                    if (index > 0)
                                    {
                                        if (sccItem.Items[index].ToString() == folderToSync)
                                        {
                                            EAS.generated.SyncResponseNamespace.SyncCollectionsCollectionCommands sccc    = null;
                                            List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7>           lstSync = new List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7>(sccItem.ItemsElementName);
                                            int indexCommand = lst.FindIndex(q => q == EAS.generated.SyncResponseNamespace.ItemsChoiceType7.Commands);

                                            if (indexCommand > -1)
                                            {
                                                if (sccItem.Items[indexCommand] is EAS.generated.SyncResponseNamespace.SyncCollectionsCollectionCommands)
                                                {
                                                    sccc = (EAS.generated.SyncResponseNamespace.SyncCollectionsCollectionCommands)sccItem.Items[indexCommand];
                                                    foreach (object o in sccc.Items)
                                                    {
                                                        if (o is EAS.generated.SyncResponseNamespace.SyncCollectionsCollectionCommandsAdd)
                                                        {
                                                            EAS.generated.SyncResponseNamespace.SyncCollectionsCollectionCommandsAdd sccca = (EAS.generated.SyncResponseNamespace.SyncCollectionsCollectionCommandsAdd)o;
                                                            lstEmailsToFetch.Add(sccca.ServerId);
                                                            OnTotalNumberOfFilesEvent(string.Format("{0} {1}", lstEmailsToFetch.Count.ToString(), _rm.GetString("strEmailsToSync")));
                                                        }
                                                    }
                                                }
                                            }

                                            int synckeyIdx = lst.FindIndex(q => q == EAS.generated.SyncResponseNamespace.ItemsChoiceType7.SyncKey);

                                            if (synckeyIdx > -1)
                                            {
                                                syncKey = sccItem.Items[synckeyIdx].ToString();
                                                syncKey = (int.Parse(syncKey)).ToString();
                                            }

                                            int moreAvailableIdx = lst.FindIndex(q => q == EAS.generated.SyncResponseNamespace.ItemsChoiceType7.MoreAvailable);
                                            if (moreAvailableIdx > -1)
                                            {
                                                continuingLoop = true;
                                            }
                                            else
                                            {
                                                continuingLoop = false;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(_rm.GetString("errSerialization"));
                    }
                }while (continuingLoop);

                WriteEmailsToDirectory(lstEmailsToFetch, folderToSync, policyKey);

                return(true);
            }
            catch (Exception ex)
            {
                kom = _rm.GetString("lblTotalGenericErrorRes") + " " + ex.Message;
                return(false);
            }
        }