Exemple #1
0
        /// <summary>
        /// Save Picture to DB
        /// </summary>
        /// <param name="rsFields">Data row</param>
        /// <param name="sFileName">File name</param>
        /// <returns>True or false</returns>
        private dynamic SavePictureToDb(DataRow rsFields, string sFileName)
        {
            bool returnValue = false;

            ADODB.Stream strStream = new ADODB.Stream();

            try
            {
                if (!File.Exists(sFileName))
                {
                    return(false);
                }

                strStream = new ADODB.Stream {
                    Type = StreamTypeEnum.adTypeBinary
                };
                strStream.Open();
                strStream.LoadFromFile(sFileName);

                rsFields["Signature"] = strStream.Read();

                returnValue = true;
            }
            catch (Exception)
            {
                // ignored
            }
            finally
            {
                strStream.Close();
            }
            return(returnValue);
        }
        //Useless -> NON ho idea di come usarla correttamente
        public static Message ReadMessage(string emlFileName)
        {
            Message msg = new Message();

            ADODB.Stream stream = new ADODB.Stream();
            stream.Open(Type.Missing, ConnectModeEnum.adModeUnknown, StreamOpenOptionsEnum.adOpenStreamUnspecified, string.Empty, string.Empty);
            stream.LoadFromFile(emlFileName);
            stream.Flush();
            msg.DataSource.OpenObject(stream, "_Stream");
            msg.DataSource.Save();
            return(msg);
        }
Exemple #3
0
 private CDO.Message GetMessage(FileInfo fileInfo)
 {
     CDO.Message  msg    = new CDO.Message();
     ADODB.Stream stream = new ADODB.Stream();
     stream.Type = StreamTypeEnum.adTypeBinary;
     stream.Open(Type.Missing, ADODB.ConnectModeEnum.adModeUnknown, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, String.Empty, String.Empty);
     stream.LoadFromFile(fileInfo.FullName);
     stream.Flush();
     msg.DataSource.OpenObject(stream, "_Stream");
     msg.DataSource.Save();
     return(msg);
 }
Exemple #4
0
        static void Main(string[] args)
        {
            string emlPath = String.Empty;

            if (args.Length > 0)
            {
                emlPath = args[0].ToString();

                string emlContent = new StreamReader(emlPath).ReadToEnd();

                CDO.Message m = new CDO.Message();
                ADODB.Stream s = new ADODB.Stream();

                s = m.GetStream();
                s.Type = ADODB.StreamTypeEnum.adTypeText;
                s.LoadFromFile(emlPath);
                s.Flush();

                if (m.To.IndexOf(ConfigurationManager.AppSettings["addressPhotos"]) >= 0)
                {
                    foreach (IBodyPart bp in m.BodyPart.BodyParts)
                    {
                        if (bp.ContentMediaType == "image/jpeg")
                        {
                            string tempFilePath = ConfigurationManager.AppSettings["temporaryFilePath"] + System.Guid.NewGuid() + ".jpg";
                            bp.GetDecodedContentStream().SaveToFile(tempFilePath, SaveOptionsEnum.adSaveCreateOverWrite);

                            StreamReader sr = new StreamReader(tempFilePath);
                            Photo p = new Photo(bp.ContentMediaType, sr.BaseStream, m.Subject, m.TextBody, String.Empty);

                            // Pass up the sending and recipient addresses as well
                            p.SenderAddress = m.Sender;
                            p.RecipientAddress = m.To;

                            // Save the image
                            p.Save();

                            sr.Dispose();
                            File.Delete(tempFilePath);
                        }
                    }
                }

                s.Close();
            }
        }