Exemple #1
0
        public int AddMessages(List<Dictionary<string, string> > lMessages)
        {
            int retval = 0;

            lastError = "";

            string uploadInfo = "";

            System.Type type = typeof (ZimbraMessage);
            FieldInfo[] myFields = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
            WebServiceClient client = new WebServiceClient {
            Url = ZimbraValues.GetZimbraValues().Url, WSServiceType =
                WebServiceClient.ServiceType.Traditional
            };
            StringBuilder sb = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.OmitXmlDeclaration = true;
            using (XmlWriter writer = XmlWriter.Create(sb, settings)) {
            writer.WriteStartDocument();
            writer.WriteStartElement("soap", "Envelope",
                "http://www.w3.org/2003/05/soap-envelope");

            WriteHeader(writer, true, true, true);

            writer.WriteStartElement("Body", "http://www.w3.org/2003/05/soap-envelope");
            writer.WriteStartElement("BatchRequest", "urn:zimbra");
            for (int i = 0; i < lMessages.Count; i++)
            {
                Dictionary<string, string> message = lMessages[i];

                ZimbraMessage zm = new ZimbraMessage("", "", "", "", "");

                for (int j = 0; j < myFields.Length; j++)       // use reflection to set ZimbraMessage object values
                {
                    string nam = (string)myFields[j].Name;

                    if (nam == "folderId")
                        myFields[j].SetValue(zm, FindFolder(message[nam]));
                    else
                        myFields[j].SetValue(zm, message[nam]);
                }

                bool isInline = false;
                if (message["wstrmimeBuffer"].Length > 0)
                {
                    //
                }
                else
                {
                    FileInfo f = new FileInfo(zm.filePath);
                    isInline = (f.Length < INLINE_LIMIT);
                }

                if (isInline)
                    uploadInfo = zm.filePath;
                else
                {
                    Log.debug("Begin UploadFile");
                    string tmp = message["wstrmimeBuffer"];
                    retval = UploadFile(zm.filePath, tmp, "", "", STRING_MODE, out uploadInfo);
                    Log.debug("End UploadFile");
                }
                if (retval == 0)
                    AddMsgRequest(writer, uploadInfo, zm, isInline, -1);
                File.Delete(zm.filePath);
            }
            writer.WriteEndElement();           // BatchRequest
            writer.WriteEndElement();           // soap body
            writer.WriteEndElement();           // soap envelope
            writer.WriteEndDocument();
            }

            string rsp = "";
            WriteSoapLog(sb.ToString(),true);

            client.InvokeService(sb.ToString(), out rsp);

            WriteSoapLog(rsp.ToString(),false);
            retval = client.status;

            return retval;
        }
Exemple #2
0
 public void AddMsgRequest(XmlWriter writer, string uploadInfo, ZimbraMessage message, bool
 isInline, int requestId)
 {
     // if isLine, uploadInfo will be a file path; if not, uploadInfo will be the upload token
     writer.WriteStartElement("AddMsgRequest", "urn:zimbraMail");
     if (requestId != -1)
     writer.WriteAttributeString("requestId", requestId.ToString());
     writer.WriteStartElement("m");
     writer.WriteAttributeString("l", message.folderId);
     writer.WriteAttributeString("d", message.rcvdDate);
     writer.WriteAttributeString("f", message.flags);
     if (message.tags.Length > 0)
     {
     writer.WriteAttributeString("t", message.tags);
     }
     if (isInline)
     {
     WriteNVPair(writer, "content", System.Text.Encoding.Default.GetString(
         File.ReadAllBytes(uploadInfo)));
     }
     else
     {
     writer.WriteAttributeString("aid", uploadInfo);
     }
     writer.WriteEndElement();               // m
     writer.WriteEndElement();               // AddMsgRequest
 }
Exemple #3
0
        public int AddMessage(Dictionary<string, string> message)
        {
            lastError = "";

            string uploadInfo = "";
            int retval = 0;
            ZimbraMessage zm = new ZimbraMessage("", "", "", "", "");

            System.Type type = typeof (ZimbraMessage);
            FieldInfo[] myFields = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
            for (int i = 0; i < myFields.Length; i++)       // use reflection to set ZimbraMessage object values
            {
            string nam = (string)myFields[i].Name;

            if (nam == "folderId")
                myFields[i].SetValue(zm, FindFolder(message[nam]));
            else
                myFields[i].SetValue(zm, message[nam]);
            }

            bool isInline = false;
            if (message["wstrmimeBuffer"].Length > 0)
            {
            //
            }
            else
            {
            FileInfo f = new FileInfo(zm.filePath);// use a try/catch?
            isInline = (f.Length < INLINE_LIMIT);
            }

            if (isInline)
            uploadInfo = zm.filePath;
            else
            {
            //Log.debug("Begin UploadFile");
            string tmp = message["wstrmimeBuffer"];
            retval = UploadFile(zm.filePath, tmp, "", "", STRING_MODE, out uploadInfo);
            //Log.debug("End UploadFile");
            }
            if (retval == 0)
            {
            WebServiceClient client = new WebServiceClient {
                Url = ZimbraValues.GetZimbraValues().Url, WSServiceType =
                    WebServiceClient.ServiceType.Traditional
            };
            StringBuilder sb = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.OmitXmlDeclaration = true;
            using (XmlWriter writer = XmlWriter.Create(sb, settings)) {
                writer.WriteStartDocument();
                writer.WriteStartElement("soap", "Envelope",
                    "http://www.w3.org/2003/05/soap-envelope");

                WriteHeader(writer, true, true, true);

                writer.WriteStartElement("Body", "http://www.w3.org/2003/05/soap-envelope");

                AddMsgRequest(writer, uploadInfo, zm, isInline, -1);

                writer.WriteEndElement();       // soap body
                writer.WriteEndElement();       // soap envelope
                writer.WriteEndDocument();
            }

            string rsp = "";
            WriteSoapLog(sb.ToString(),true);

            client.InvokeService(sb.ToString(), out rsp);

            WriteSoapLog(rsp.ToString(),false);
            retval = client.status;
            if (client.status == 0)
            {
                string mID = "";

                ParseAddMsg(rsp, out mID);      // get the id
            }
            else
            {
                string soapReason = ParseSoapFault(client.errResponseMessage);
                string errMsg = (soapReason.IndexOf("upload ID: null") != -1)    // FBS bug 75159 -- 6/7/12
                                ? "Unable to upload file. Please check server message size limits (Global Settings General Information and MTA)."
                                : soapReason;
                if (soapReason.Length > 0)
                {
                    lastError = soapReason;
                    Log.err("Error on message", message["Subject"], "--", errMsg);
                }
                else
                {
                    lastError = client.exceptionMessage;
                }
            }
            }
            //File.Delete(zm.filePath);
            return retval;
        }