Ejemplo n.º 1
0
 /**
  * Performs Base64 encoding or decoding on the data written to the
  * stream, writing the encoded/decoded data to another
  * OutputStream.
  *
  * @param out the OutputStream to write the encoded data to
  * @param flags bit flags for controlling the encoder; see the
  *        constants in {@link Base64}
  * @param encode true to encode, false to decode
  *
  * @hide
  */
 public Base64OutputStream(Stream sout, int flags, bool encode)
 {
     this.sout  = sout;
     this.flags = flags;
     if (encode)
     {
         coder = new Base64.Encoder(flags, null);
     }
     else
     {
         coder = new Base64.Decoder(flags, null);
     }
 }
Ejemplo n.º 2
0
        private static bool getPostDataEmailOperations(Stream s, string msgId, string boundary, string to, string subject, DateTime fecha, string pathPDF)
        {
            if (subject != null && subject.Length > 0)
            {
                subject = Utility.encodeSubjectText(subject);
            }
            SimpleSMTPHeader sheader = new SimpleSMTPHeader(Global.getEmailPublicoGeneral(), subject);

            Utility.writeBytes(s, "--" + boundary + "\r\n");
            Utility.writeBytes(s, "Content-Type: application/json; charset=UTF-8\r\n\r\n");
            Utility.writeBytes(s, "{\r\n}\r\n\r\n");
            Utility.writeBytes(s, "--" + boundary + "\r\n");
            Utility.writeBytes(s, "Content-Type: message/rfc822\r\n\r\n");
            string   boundaryEmail = string.Empty;
            DateTime dt            = DateTime.Now;

            fillEmailGmailApi(s, sheader, ref boundaryEmail, msgId, dt, to, subject, fecha);
            byte[]       buffer = null;
            Base64.Coder coder  = null;
            try
            {
                string[] files = new string[1];
                files[0] = pathPDF;
                int read = 0;
                for (int i = 0; i < 1; i++)
                {
                    FileInfo info = new FileInfo(files[i]);
                    coder = new Base64.Encoder(Base64.CRLF | Base64.NO_CLOSE, null);
                    s.Write(CRLF, 0, CRLF.Length);
                    Utility.writeBytes(s, "------" + boundaryEmail + "\r\n");
                    Utility.writeBytes(s, "Content-Type: application/octet-stream\r\n");
                    Utility.writeBytes(s, "Content-Transfer-Encoding: base64\r\n");
                    Utility.writeBytes(s, "Content-Disposition: attachment; filename=\"" + Utility.encodeText(info.Name) + "\"\r\n\r\n");
                    buffer = new byte[8192];
                    read   = 0;
                    using (FileStream fs = new FileStream(files[i], FileMode.Open, FileAccess.Read))
                    {
                        while ((read = fs.Read(buffer, 0, 8192)) > 0)
                        {
                            if (read >= 8192)
                            {
                                coder.process(buffer, 0, read, false, s);
                            }
                            else
                            {
                                coder.process(buffer, 0, read, true, s);
                            }
                        }
                        fs.Dispose();
                    }
                    s.Write(CRLF, 0, CRLF.Length);
                    coder = null;
                    info  = null;
                }
                buffer = new byte[8192];
                read   = 0;
                coder  = new Base64.Encoder(Base64.CRLF | Base64.NO_CLOSE, null);
                s.Write(CRLF, 0, CRLF.Length);
                Utility.writeBytes(s, "------" + boundaryEmail + "\r\n");
                Utility.writeBytes(s, "Content-Type: image/png\r\n");
                Utility.writeBytes(s, "Content-Transfer-Encoding: base64\r\n");
                Utility.writeBytes(s, "Content-Disposition: inline; filename=\"" + Utility.encodeText("recyclame.png") + "\"\r\n");
                Utility.writeBytes(s, "Content-ID: <logo>\r\n\r\n");
                using (var img = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Recyclame.Resources.recyclame.fw.jpeg"))
                {
                    using (BinaryReader reader = new BinaryReader(img))
                    {
                        while ((read = reader.Read(buffer, 0, 8192)) > 0)
                        {
                            coder.process(buffer, 0, read, false, s);
                        }
                        reader.Dispose();
                    }
                }
                s.Write(CRLF, 0, CRLF.Length);
                coder = null;

                Utility.writeBytes(s, "------" + boundaryEmail + "--\r\n");
                Utility.writeBytes(s, "--" + boundary + "--\r\n");
                s.Flush();
                return(true);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("EMAIL OPERATION POST DATA EXCEPTION: " + e.ToString());
            }
            return(false);
        }