Пример #1
0
        internal static byte[] ConvertAttachment(string strDesc, byte[] pbData)
        {
            BinaryDataClass bdc = BinaryDataClassifier.Classify(strDesc, pbData);

            if (bdc == BinaryDataClass.Text)
            {
                string strContext = (KPRes.File + (string.IsNullOrEmpty(strDesc) ?
                                                   string.Empty : (": " + strDesc)));

                TextEncodingForm dlg = new TextEncodingForm();
                dlg.InitEx(strContext, pbData);
                if (UIUtil.ShowDialogNotValue(dlg, DialogResult.OK))
                {
                    return(null);
                }

                Encoding enc    = dlg.SelectedEncoding;
                int      iStart = (int)dlg.DataStartOffset;
                UIUtil.DestroyForm(dlg);
                if (enc != null)
                {
                    try
                    {
                        string strText = (enc.GetString(pbData, iStart,
                                                        pbData.Length - iStart) ?? string.Empty);
                        strText = StrUtil.ReplaceNulls(strText);
                        return(StrUtil.Utf8.GetBytes(strText));
                    }
                    catch (Exception) { Debug.Assert(false); }
                }
            }

            return(pbData);
        }
Пример #2
0
        internal static byte[] ConvertAttachment(string strDesc, byte[] pbData)
        {
            BinaryDataClass bdc = BinaryDataClassifier.Classify(strDesc, pbData);

            if (bdc == BinaryDataClass.Text)
            {
                string strContext = (KPRes.File + (string.IsNullOrEmpty(strDesc) ?
                                                   string.Empty : (": " + strDesc)));

                TextEncodingForm dlg = new TextEncodingForm();
                dlg.InitEx(strContext, pbData);
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    Encoding enc = dlg.SelectedEncoding;
                    if (enc != null)
                    {
                        try
                        {
                            string strText = enc.GetString(pbData);
                            return((new UTF8Encoding(false)).GetBytes(strText));
                        }
                        catch (Exception) { Debug.Assert(false); }
                    }
                }
                else
                {
                    return(null);
                }
            }

            return(pbData);
        }
Пример #3
0
        internal static byte[] ConvertAttachment(string strDesc, byte[] pbData)
        {
            BinaryDataClass bdc = BinaryDataClassifier.Classify(strDesc, pbData);
            if(bdc == BinaryDataClass.Text)
            {
                string strContext = (KPRes.File + (string.IsNullOrEmpty(strDesc) ?
                    string.Empty : (": " + strDesc)));

                TextEncodingForm dlg = new TextEncodingForm();
                dlg.InitEx(strContext, pbData);
                if(UIUtil.ShowDialogNotValue(dlg, DialogResult.OK)) return null;

                Encoding enc = dlg.SelectedEncoding;
                UIUtil.DestroyForm(dlg);
                if(enc != null)
                {
                    try
                    {
                        string strText = enc.GetString(pbData);
                        return StrUtil.Utf8.GetBytes(strText);
                    }
                    catch(Exception) { Debug.Assert(false); }
                }
            }

            return pbData;
        }