public EncodeParameters(
     FormatId format,
     int?quality       = null,
     EncodeFlags flags = default)
 {
     Format  = format;
     Quality = quality;
     Flags   = flags;
 }
Exemple #2
0
        // Left public because testing console needs this
        public static string ProcessEmailAddresses(Encoding encoding, string addresses)
        {
            StringBuilder new_addresses = new StringBuilder();

            string[] address_array = addresses.Split(',', ';');

            EncodeFlags flags = EncodeFlags.SingleLine | EncodeFlags.QuotedPrintable;

            foreach (string address_item in address_array)
            {
                string new_address_item = EmailHelper.TrimHeaderLine(EmailHelper.RemoveControlCodes(address_item));
                new_address_item = EmailFunctions.EncloseEmail(new_address_item);

                if (new_address_item.Length > 0)
                {
                    if (new_address_item.IndexOf("<") > 0)
                    {
                        string desc    = new_address_item.Substring(0, new_address_item.IndexOf("<") - 1);
                        string address = new_address_item.Substring(new_address_item.IndexOf("<") - 1, new_address_item.Length - new_address_item.IndexOf("<") + 1);
                        if (address != null)
                        {
                            address = EmailHelper.TrimHeaderLine(address);
                        }
                        if (EmailEncoding.NeedsEncoding(encoding, desc, flags))
                        {
                            new_addresses.Append(", " + EmailEncoding.EncodeString(encoding, desc, flags) + address);
                        }
                        else
                        {
                            new_addresses.Append(", " + new_address_item);
                        }
                    }
                    else
                    {
                        new_addresses.Append(", " + new_address_item);
                    }
                }
            }
            return(new_addresses.ToString().TrimStart(',').TrimStart());
        }
Exemple #3
0
 /// <summary>
 /// Starts encoding on a channel.
 /// </summary>
 /// <param name="Handle">The channel Handle... a HSTREAM, HMUSIC, or HRECORD.</param>
 /// <param name="CommandLine">The encoder command-line, including the executable filename and any options. Or the output filename if the <see cref="EncodeFlags.PCM"/> flag is specified.</param>
 /// <param name="Flags">A combination of <see cref="BassFlags"/>.</param>
 /// <param name="Procedure">Optional callback function to receive the encoded data... <see langword="null" /> = no callback. To have the encoded data received by a callback function, the encoder needs to be told to output to STDOUT (instead of a file).</param>
 /// <param name="User">User instance data to Password to the callback function.</param>
 /// <param name="Limit">The maximum number of bytes that will be encoded (0 = no limit).</param>
 /// <returns>The encoder process Handle is returned if the encoder is successfully started, else 0 is returned (use <see cref="Bass.LastError" /> to get the error code).</returns>
 /// <remarks>
 /// <para>
 /// This function works exactly like <see cref="EncodeStart(int,string,EncodeFlags,EncodeProcedure,IntPtr)" />, but with a <paramref name="Limit" /> parameter added, which is the maximum number of bytes that will be encoded (0=no limit).
 /// Once the limit is hit, the encoder will die.
 /// <see cref="EncodeSetNotify" /> can be used to be notified of that occurrence.
 /// One thing to note is that the limit is applied after any conversion due to the floating-point flags.
 /// </para>
 /// <para>This can be useful in situations where the encoder needs to know in advance how much data it will be receiving. For example, when using a callback function with a file format that stores the length in the header, as the header cannot then be updated at the end of encoding. The length is communicated to the encoder via the WAVE header, so it requires that the BASS_ENCODE_NOHEAD flag is not used.</para>
 /// <para>
 /// The encoder must be told (via the command-line) to expect input from STDIN, rather than a file.
 /// The command-line should also tell the encoder what filename to write it's output to, unless you're using a callback function, in which case it should be told to write it's output to STDOUT.
 /// </para>
 /// <para>
 /// No user interaction with the encoder is possible, so anything that would cause the encoder to require the user to press any keys should be avoided.
 /// For example, if the encoder asks whether to overwrite files, the encoder should be instructed to always overwrite (via the command-line), or you should delete the existing file before starting the encoder.
 /// </para>
 /// <para>
 /// Standard RIFF files are limited to a little over 4GB in size.
 /// When writing a WAV file, BASSenc will automatically stop at that point, so that the file is valid.
 /// That does not apply when sending data to an encoder though, as the encoder may (possibly via a command-line option) ignore the size restriction, but if it does not, it could mean that the encoder stops after a few hours (depending on the sample format).
 /// If longer encodings are needed, the <see cref="EncodeFlags.NoHeader"/> flag can be used to omit the WAVE header, and the encoder informed of the sample format via the command-line instead.
 /// The 4GB size limit can also be overcome with the <see cref="EncodeFlags.RF64"/> flag, but most encoders are unlikely to support RF64.
 /// </para>
 /// <para>
 /// When writing an RF64 WAV file, a standard RIFF header will still be written initially, which will only be replaced by an RF64 header at the end if the file size has exceeded the standard limit.
 /// When an encoder is used, it is not possible to go back and change the header at the end, so the RF64 header is sent at the beginning in that case.
 /// </para>
 /// <para>
 /// Internally, the sending of sample data to the encoder is implemented via a DSP callback on the channel.
 /// That means when you play the channel (or call <see cref="Bass.ChannelGetData(int,IntPtr,int)" /> if it's a decoding channel), the sample data will be sent to the encoder at the same time.
 /// It also means that if you use the <see cref="Bass.FloatingPointDSP"/> option, then the sample data will be 32-bit floating-point, and you'll need to use one of the Floating-point flags if the encoder does not support floating-point sample data.
 /// The <see cref="Bass.FloatingPointDSP"/> setting should not be changed while encoding is in progress.
 /// </para>
 /// <para>The encoder DSP has a priority setting of -1000, so if you want to set DSP/FX on the channel and have them present in the encoding, set their priority above that.</para>
 /// <para>
 /// Besides the automatic DSP system, data can also be manually fed to the encoder via the <see cref="EncodeWrite(int,IntPtr,int)" /> function.
 /// Both methods can be used together, but in general, the "automatic" system ought be paused when using the "manual" system, by use of the <see cref="EncodeFlags.Pause"/> flag or the <see cref="EncodeSetPaused" /> function.
 /// </para>
 /// <para>
 /// When queued encoding is enabled via the <see cref="EncodeFlags.Queue"/> flag, the DSP system or <see cref="EncodeWrite(int,IntPtr,int)" /> call will just buffer the data, and the data will then be fed to the encoder by another thread.
 /// The buffer will grow as needed to hold the queued data, up to a limit specified by the <see cref="Queue"/> config option.
 /// If the limit is exceeded (or there is no free memory), data will be lost; <see cref="EncodeSetNotify(int,EncodeNotifyProcedure,IntPtr)" /> can be used to be notified of that occurrence.
 /// The amount of data that is currently queued, as well as the queue limit and how much data has been lost, is available from <see cref="EncodeGetCount(int,EncodeCount)" />.
 /// </para>
 /// <para>
 /// <see cref="EncodeIsActive" /> can be used to check that the encoder is still running.
 /// When done encoding, use <see cref="EncodeStop(int)" /> to close the encoder.
 /// </para>
 /// <para>The returned process Handle can be used to do things like change the encoder's priority and get it's exit code.</para>
 /// <para>
 /// Multiple encoders can be set on a channel.
 /// For simplicity, the encoder functions will accept either an encoder Handle or a channel Handle.
 /// When using a channel Handle, the function is applied to all encoders that are set on that channel.
 /// </para>
 /// <para><b>Platform-specific</b></para>
 /// <para>External encoders are not supported on iOS or Windows CE, so only plain PCM file writing with the <see cref="EncodeFlags.PCM"/> flag is possible on those platforms.</para>
 /// </remarks>
 /// <exception cref="Errors.Handle"><paramref name="Handle" /> is not valid.</exception>
 /// <exception cref="Errors.FileOpen">Couldn't start the encoder. Check that the executable exists.</exception>
 /// <exception cref="Errors.Create">The PCM file couldn't be created.</exception>
 /// <exception cref="Errors.Unknown">Some other mystery problem!</exception>
 public static int EncodeStart(int Handle, string CommandLine, EncodeFlags Flags, EncodeProcedure Procedure, IntPtr User, int Limit)
 {
     return(BASS_Encode_StartLimit(Handle, CommandLine, Flags | EncodeFlags.Unicode, Procedure, User, Limit));
 }
Exemple #4
0
 public static extern int EncodeStartACM(int handle, IntPtr form, EncodeFlags flags, EncodeProcedure proc, IntPtr user);
Exemple #5
0
 static extern int BASS_Encode_OGG_StartFile(int Handle, string Options, EncodeFlags Flags, string FileName);
Exemple #6
0
 static extern int BASS_Encode_OGG_Start(int Handle, string Options, EncodeFlags Flags, EncodeProcedure Procedure, IntPtr User);
        private static string QP_Encode(System.Text.Encoding encoding, byte[] buffer, EncodeFlags flags)
        {
            string        heading      = "=?" + encoding.HeaderName + "?Q?";
            string        terminator   = "?=";
            string        lwsp         = "\r\n\t"; // linear-white-space
            bool          isSingleLine = (flags & EncodeFlags.SingleLine) == EncodeFlags.SingleLine;
            StringBuilder buf          = new StringBuilder();
            int           encodedcount = 0;
            sbyte         cur;

            buf.Append(heading);
            encodedcount += heading.Length;

            for (int x = 0; x < buffer.Length; x++)
            {
                cur = (sbyte)buffer[x];
                //is this a valid ascii character?
                bool processed = false;
                bool doit      = false;
                if (((cur >= 33) && (cur <= 60)) || ((cur >= 62) && (cur <= 126)) || (cur == '\r') || (cur == '\n') || (cur == '\t') || (cur == ' '))
                {
                    if ((cur == '\r') || (cur == '\n'))
                    {
                        // When encoding a single line field escape the newline chars
                        if ((flags & EncodeFlags.MultiLine) == EncodeFlags.MultiLine)
                        {
                            doit = true;
                        }
                    }
                    else if (cur == 63)     // '?'
                    // We must escape this char as it is not allowed
                    {
                        doit = false;
                    }
                    else if ((cur == ' ') || (cur == '\t') || (cur == '_'))     // '?'
                    // We must escape these chars as it is not allowed
                    {
                        doit = false;
                    }
                    else
                    {
                        doit = true;
                    }
                    if (doit)
                    {
                        if (!isSingleLine && encodedcount + 2 + 1 > MaxEncodedLength)   // 2 for the terminator, 1 for the char
                        {
                            buf.Append(terminator);
                            buf.Append(lwsp);
                            buf.Append(heading);
                            encodedcount = heading.Length;
                        }
                        buf.Append((char)buffer[x]);
                        encodedcount++;
                        processed = true;
                    }
                }
                if (!processed)
                {
                    if (!isSingleLine && encodedcount + 2 + 3 > MaxEncodedLength)   // 2 for the terminator, 3 for the chars
                    {
                        buf.Append(terminator);
                        buf.Append(lwsp);
                        buf.Append(heading);
                        encodedcount = heading.Length;
                    }
                    buf.Append('=');
                    buf.Append(((sbyte)((cur & 0xF0) >> 4)).ToString("X"));
                    buf.Append(((sbyte)(cur & 0x0F)).ToString("X"));
                    encodedcount += 3;
                }
            }
            buf.Append(terminator);

            //format data so that lines don't end with spaces (if so, add a trailing '='), etc.
            //for more detail see RFC 2045.

            int    start = 0;
            string enc   = buf.ToString();

            buf.Length = 0;
            for (int x = 0; x < enc.Length; ++x)
            {
                cur = (sbyte)enc[x];
                if (cur == '\n' || cur == '\r' || x == (enc.Length - 1))
                {
                    buf.Append(enc.Substring(start, x - start + 1));
                    start = x + 1;
                    continue;
                }
                if (!isSingleLine && (x - start) > MaxEncodedLength)
                {
                    bool inWord = true;
                    while (inWord)
                    {
                        inWord = (!char.IsWhiteSpace(enc, x) && enc[x - 2] != '=');
                        if (inWord)
                        {
                            --x;
                            cur = (sbyte)enc[x];
                        }
                        if (x == start)
                        {
                            x = start + MaxEncodedLength;
                            break;
                        }
                    }
                    buf.Append(enc.Substring(start, x - start + 1));
                    buf.Append("=\r\n");
                    start = x + 1;
                }
            }
            return(buf.ToString());
        }
 // This is used to MIME encode a string in Base64
 // 2004-07-08 MRC This method is broken, by the spec we should limit each 'encoded-text' to max 75 chars
 //                and create several 'encoded-texts' separated by 'linear-white-space'.
 //                I'm not fixing this at this time. Maybe later if it is needed.
 internal static string EncodeString(System.Text.Encoding encoding, string text, EncodeFlags flags)
 {
     if ((flags & EncodeFlags.Base64) == EncodeFlags.Base64)
     {
         throw new ArgumentException("Unsupported encoding");
     }
     else if ((flags & EncodeFlags.QuotedPrintable) == EncodeFlags.QuotedPrintable)
     {
         return(EncodeAsQuotedPrintable(encoding, text, flags));
     }
     else
     {
         throw new InvalidOperationException("Unsupported encoding");
     }
 }
        /// <summary>
        /// Encode the body as in quoted-printable format.
        /// Adapted from PJ Naughter's quoted-printable encoding code.
        /// For more information see RFC 2045.
        /// </summary>
        /// <returns>The encoded body.</returns>
        private static string EncodeAsQuotedPrintable(System.Text.Encoding encoding, string text, EncodeFlags flags)
        {
            StringBuilder buf        = new StringBuilder();
            string        heading    = "=?" + encoding.HeaderName + "?Q?";
            string        terminator = "?=";
            string        lwsp       = "\r\n\t"; // linear-white-space
            int           start      = 0;

            if ((flags & EncodeFlags.SingleLine) == EncodeFlags.SingleLine)
            {
                return(QP_Encode(encoding, encoding.GetBytes(text), flags));
            }
            else
            {
                while (start < text.Length)
                {
                    byte[] buffer   = null;
                    int    tsize    = MaxEncodedLength + 1;
                    int    tbufsize = 0;
                    tbufsize = MaxEncodedLength - heading.Length - terminator.Length;
                    if (start + tbufsize > text.Length)
                    {
                        tbufsize = text.Length - start;
                    }
                    while (tsize > MaxEncodedLength)
                    {
                        if (start + tbufsize > text.Length)
                        {
                            tbufsize = text.Length - start;
                        }
                        buffer = encoding.GetBytes(text.Substring(start, tbufsize));
                        tsize  = QP_CalcSize(encoding, buffer, flags);
                        if (tsize > MaxEncodedLength)
                        {
                            // Reduce the size and try again
                            tbufsize--;
                        }
                    }
                    if (start != 0)
                    {
                        buf.Append(lwsp);
                    }
                    buf.Append(QP_Encode(encoding, buffer, flags));
                    start += tbufsize;
                }

                return(buf.ToString());
            }
        }
Exemple #10
0
 static extern int BASS_Encode_StartACMFile(int handle, IntPtr form, EncodeFlags flags, string filename);
Exemple #11
0
 public static extern int EncodeStartACM(int Handle, IntPtr Format, EncodeFlags Flags, EncodeProcedure Procedure, IntPtr User = default(IntPtr));
Exemple #12
0
        /// <summary>
        /// Initializes the production of an email message, creating its headers and main body. Note that this
        /// action does not immediately send the message, as you may want to add futher parts (attachments) to
        /// it (using <see cref="AddPart" />). To finalize message and send it you should then call RichMailSend
        /// </summary>
        /// <remarks>
        /// Older emails clients (such as some versions of Lotus and Outlook 2000) do not correctly support the MIME encoding used to send HTML emails. To enable HTML emails to be delivered correctly to these clients you can add &quot;lotus/compatible&quot; (without the quotes) to the ContentType. This will change how the whole email is created and allows those clients to shows the message properly at the expense of more recent email clients (such as Yahoo! Mail) that will not display the message correctly.
        /// </remarks>
        /// <param name="processAddresses">Pre-process the email addresses?</param>
        /// <param name="ssFrom">Email address of the sender</param>
        /// <param name="ssTo">Email addresses to send the email to (comma separated)</param>
        /// <param name="headers">Email header information</param>
        /// <param name="ssCc">Email addresses to carbon-copy the email to (comma separated)</param>
        /// <param name="ssBcc">Email addresses to blind carbon-copy the email to (comma separated)</param>
        /// <param name="ssContentType">MIME type of the message.</param>
        /// <param name="ssCharset">Character used in the message text</param>
        /// <param name="ssSubject">Subject of the message</param>
        /// <param name="ssBody">Text content of the message</param>
        /// <param name="ssBodyIsHtml">TRUE if content of the message is HTML rather than plain text</param>
        /// <param name="ssUrl">Base URL to use in case the Body is HTML. This allows any relative paths that may exist in the Body to be expanded to full blown URL's</param>
        /// <param name="ssIncludeImages">If TRUE, any images referenced via an URL in the Body are attached to the message</param>
        /// <param name="ssInReplyTo">Alternate reply-to email address</param>
        /// <param name="userAgent">User agent to use to request the email messages.</param>
        /// <param name="realHostname">The hostname to use when building links in the email body.</param>
        /// <param name="zoneAddress">Deploymentzoneadress of the running espace</param>
        /// <param name="ssBoundary">System marker that should be passed in to any further parts that are added to this message (see <see cref="AddPart" />).</param>
        /// <param name="ssMail">The full message text produced by the call</param>
        /// <param name="emailId">The created email id.</param>
        public static void CreateEmail(bool processAddresses, string ssFrom, string ssTo, List <String> headers, string ssCc, string ssBcc, string ssContentType, string ssCharset, string ssSubject, string ssBody, bool ssBodyIsHtml, string ssUrl, bool ssIncludeImages, string ssInReplyTo, string userAgent, string realHostname, string zoneAddress, out string ssBoundary, out string ssMail, out string emailId)
        {
            bool prepareMimeEncoding = true;
            //string base64 = null;
            bool use_multipart_related = true;

            ssBoundary = "";
            System.Text.StringBuilder sbMail = new System.Text.StringBuilder();

            if (realHostname == null)
            {
                throw new InvalidOperationException("The 'Default DNS Name' must be set in Service Center's Environment Configuration to send emails.");
            }

            // Cleanup the content type
            ssContentType = EmailHelper.TrimHeaderLine(ssContentType);

            // This is a hack to support Outlook 2000 and other clients
            // that do not support multipart/related.
            int tpos = ssContentType.ToUpper().IndexOf("LOTUS/COMPATIBLE");

            if (tpos >= 0)
            {
                ssContentType         = ssContentType.Remove(tpos, 16);
                use_multipart_related = false;
            }

            // If no Content Type defined, set it to "multipart/mixed"
            if (ssContentType == "")
            {
                ssContentType = "multipart/mixed";
            }

            if (!ssContentType.ToLower().StartsWith("multipart"))
            {
                // If it's not a multipart message then don't encase in MIME containers
                prepareMimeEncoding = false;
            }

            if (ssBodyIsHtml)
            {
                prepareMimeEncoding = true;
            }

            // If no Content Type defined, set it to "multipart/mixed"
            if (ssCharset == "")
            {
                ssCharset = "iso-8859-1";
            }
            else
            {
                ssCharset = EmailHelper.TrimHeaderLine(ssCharset);
            }

            // Get a correct encoder
            System.Text.Encoding mailEncoding = System.Text.Encoding.GetEncoding(ssCharset);

            if (prepareMimeEncoding)
            {
                // Get a random boundary
                ssBoundary = EmailHelper.CreateRandomBoundary();
            }
            else
            {
                ssBoundary = "";
            }

            // Add date to email header
            sbMail.Append("Date: ");
            sbMail.Append(EmailHelper.GetEmailDate(System.DateTime.Now));
            sbMail.Append("\r\n");

            if (processAddresses)
            {
                ssFrom = EmailHelper.ProcessEmailAddresses(mailEncoding, ssFrom);
            }

            emailId = System.Guid.NewGuid().ToString().Replace("-", "") + "@" + RuntimePlatformSettings.EMail.ServerHost.GetValue();
            // Add the EmailID
            sbMail.Append("Message-ID: <" + emailId + ">\r\n");


            // Add from to email header
            sbMail.Append("From: ");
            sbMail.Append(ssFrom);
            sbMail.Append("\r\n");

            if (processAddresses)
            {
                // If any of the email addresses in the To field are in the format
                // "description <email address>", then encode with iso-8859-1 the description.
                ssTo = EmailHelper.ProcessEmailAddresses(mailEncoding, ssTo);
            }

            // Add to to email header
            sbMail.Append("To: ");
            sbMail.Append(ssTo);
            sbMail.Append("\r\n");

            // Add headers

            if (headers != null)
            {
                foreach (String header in headers)
                {
                    sbMail.Append(header);
                    sbMail.Append("\r\n");
                }
            }

            // If cc not empty, add it to email header
            if (ssCc != "")
            {
                if (processAddresses)
                {
                    // If any of the email addresses in the Cc field are in the format
                    // "description <email address>", then encode with iso-8859-1 the description.
                    ssCc = EmailHelper.ProcessEmailAddresses(mailEncoding, ssCc);
                }

                // Add it to the email header
                sbMail.Append("Cc: ");
                sbMail.Append(ssCc);
                sbMail.Append("\r\n");
            }

            ssInReplyTo = EmailHelper.TrimHeaderLine(ssInReplyTo);

            // Add In-Reply-To to email header
            if (ssInReplyTo != "")
            {
                sbMail.Append("In-Reply-To:");
                sbMail.Append(ssInReplyTo);
                sbMail.Append("\r\n");
            }

            ssSubject = EmailHelper.TrimHeaderLine(ssSubject);

            EncodeFlags headerEncodeFlags = EncodeFlags.SingleLine | EncodeFlags.QuotedPrintable;

            // Encode the subject
            if (EmailEncoding.NeedsEncoding(mailEncoding, ssSubject, headerEncodeFlags))
            {
                ssSubject = EmailEncoding.EncodeString(mailEncoding, ssSubject, headerEncodeFlags);
            }

            // Add subject to email header
            sbMail.Append("Subject: ");
            sbMail.Append(ssSubject);
            sbMail.Append("\r\n");

            // Add content type to email header
            if (prepareMimeEncoding)
            {
                sbMail.Append("MIME-Version: 1.0\r\n");
            }
            if (prepareMimeEncoding)
            {
                sbMail.Append("Content-Type: " + ssContentType + "; boundary=\"" + ssBoundary + "\"\r\n");
            }
            else
            {
                sbMail.Append("Content-Type: " + ssContentType + "; charset=\"" + ssCharset + "\"\r\n");
                sbMail.Append("Content-Transfer-Encoding: base64\r\n");
            }

            //sbMail += "Content-Transfer-Encoding: base64\r\n";
            if (prepareMimeEncoding)
            {
                sbMail.Append("\r\n");

                // For older clients to display something
                sbMail.Append("This is a multi-part message in MIME format.\r\n");

                // Dump the starting boundary
                sbMail.Append("--" + ssBoundary + "\r\n");
            }

            // Add body header to email
            //System.Text.Encoding bodyEncoding = System.Text.Encoding.GetEncoding(ssCharset);
            if (ssBodyIsHtml)
            {
                // Outlook 2000 is too old by now and treats emails using MULTIPART/RELATED as
                // MULTIPART/MIXED (which is standards compliant).
                // Thus if a tree like the following is used it will show an empty email
                // with two attachments. The first attachment is an email and a second one is the attachment file.
                //   Begin Message
                //     Begin Mixed Content
                //       Begin Related Contnt
                //         Begin Alternative Content
                //           Plain text message
                //           HTML Message message
                //         End Alternative Content
                //         Image
                //       End Related Content
                //       Attachment
                //     End Mixed Content
                //   End Message
                //
                // To avoid this we now have a flag that disables the use of MULTIPART/RELATED
                // and uses a tree like this :
                //   Begin Message
                //     Begin Mixed Content
                //       Begin Alternative Content
                //         Plain text message
                //         HTML Message message
                //       End Alternative Content
                //       Image
                //       Attachment
                //     End Mixed Content
                //   End Message

                string relatedBoundary = null;
                if (use_multipart_related)
                {
                    relatedBoundary = EmailHelper.CreateRandomBoundary();
                }

                string           alternateBoundary = EmailHelper.CreateRandomBoundary();
                string           normBody;
                Hashtable        uri2cidMap;
                StringCollection uris;

                // remove meta content type
                normBody = ScriptableEmailFunctions.GetRegex("<meta +http-equiv='?\"?content-type[^>]+>", RegexOptions.IgnoreCase).Replace(ssBody, "");

                // Place stylesheet inline
                var match = ScriptableEmailFunctions.GetRegex("<link [^>]*href=\"([^\"]+\\.css)(\\?[0-9_]+)?\"[^>]*>", RegexOptions.IgnoreCase).Match(normBody);
                if (match.Success)
                {
                    string css;
                    Uri    absUri = null;
                    try {
                        absUri = new Uri(new Uri(ssUrl), match.Groups[1].Value);
                    } catch { }
                    if (absUri != null)
                    {
                        string cssEncoding;
                        EmailHelper.HttpGet(absUri.AbsoluteUri, MailUA, null, out css, out cssEncoding);
                        css      = EmailHelper.NormalizeCSS(css);
                        normBody = normBody.Substring(0, match.Index) + "<style>" + css + "</style>" + normBody.Substring(match.Index + match.Length, normBody.Length - match.Index - match.Length);
                    }
                }

                string returnBody;
                EmailHelper.HtmlProcessPaths(normBody, ssUrl, ssIncludeImages, use_multipart_related, out returnBody, out uris, out uri2cidMap);
                normBody = returnBody;

                // Replace localhost with the real name for any unescaped link that occurred (normal destinations are already ok)
                if (realHostname != null)   //just for sanity check
                {
                    normBody = ReplaceLinksWithEnvAddress(realHostname, zoneAddress, normBody);
                }

                string images = EmailHelper.HtmlFetchImages(ssIncludeImages, ssBoundary, use_multipart_related, relatedBoundary, uri2cidMap, userAgent);
                EmailHelper.HtmlAppendImages(ssCharset, EmailEncoding.MaxEncodedLength, use_multipart_related, sbMail, mailEncoding, relatedBoundary, alternateBoundary, normBody, images);
            }
            else if (ssBody != "")
            {
                if (prepareMimeEncoding)
                {
                    sbMail.Append("Content-Type: text/plain; charset=\"" + ssCharset + "\"\r\n");
                    sbMail.Append("Content-Transfer-Encoding: base64\r\n");
                }
                sbMail.Append("\r\n");

                // Encode body and add it to the email
                sbMail.Append(EmailEncoding.GetBase64TextBlock(mailEncoding.GetBytes(ssBody), EmailEncoding.MaxEncodedLength));
            }
            else
            {
                sbMail.Append("\r\n");
            }

            ssMail = sbMail.ToString();
        } // CreateEmail
Exemple #13
0
 public static extern int EncodeStartCA(int handle, int fytpe, int atype, EncodeFlags flags, int bitrate, [MarshalAs(UnmanagedType.LPStr)] string filename);
Exemple #14
0
 public static extern int EncodeStartCA(int handle, int fytpe, int atype, EncodeFlags flags, int bitrate, EncodeProcedureEx proc, IntPtr user);
Exemple #15
0
 public static extern int EncodeStartACM(int handle, IntPtr form, EncodeFlags flags, [MarshalAs(UnmanagedType.LPStr)] string filename);
Exemple #16
0
 static extern int BASS_Encode_StartUser(int handle, string filename, EncodeFlags flags, EncoderProcedure proc, IntPtr user);
Exemple #17
0
 /// <summary>
 /// Sets up a user-provided encoder on a channel.
 /// </summary>
 /// <param name="Handle">The channel handle... a HSTREAM, HMUSIC, or HRECORD.</param>
 /// <param name="Filename">Output filename... <see langword="null" /> = no output file.</param>
 /// <param name="Flags">A combination of <see cref="EncodeFlags"/>.</param>
 /// <param name="Procedure">Callback function to receive the sample data and return the encoded data.</param>
 /// <param name="User">User instance data to Password to the callback function.</param>
 /// <returns>The encoder process handle is returned if the encoder is successfully started, else 0 is returned (use <see cref="Bass.LastError" /> to get the error code).</returns>
 /// <remarks>
 /// <para>
 /// This function allows user-provided encoders to be used, which is most useful for platforms where external encoders are unavailable
 /// for use with <see cref="EncodeStart(int,string,EncodeFlags,EncodeProcedure,IntPtr)" />.
 /// For example, the LAME library could be used with this function instead of the standalone LAME executable with <see cref="EncodeStart(int,string,EncodeFlags,EncodeProcedure,IntPtr)" />.
 /// </para>
 /// <para>
 /// Internally, the sending of sample data to the encoder is implemented via a DSP callback on the channel.
 /// That means when the channel is played (or <see cref="Bass.ChannelGetData(int,IntPtr,int)" /> is called if it is a decoding channel), the sample data will be sent to the encoder at the same time.
 /// It also means that if the <see cref="Bass.FloatingPointDSP"/> option is enabled, the sample data will be 32-bit floating-point, and one of the floating-point flags will be required if the encoder does not support floating-point sample data.
 /// The <see cref="Bass.FloatingPointDSP"/> setting should not be changed while encoding is in progress.
 /// </para>
 /// <para>
 /// By default, the encoder DSP has a priority setting of -1000, which determines where in the DSP chain the encoding is performed.
 /// That can be changed via the <see cref="DSPPriority"/> config option.
 /// </para>
 /// <para>
 /// Besides the automatic DSP system, data can also be manually fed to the encoder via the <see cref="EncodeWrite(int,IntPtr,int)" /> function.
 /// Both methods can be used together, but in general, the 'automatic' system ought to be paused when using the 'manual' system, via the <see cref="EncodeFlags.Pause"/> flag or the <see cref="EncodeSetPaused" /> function.
 /// Data fed to the encoder manually does not go through the source channel's DSP chain, so any DSP/FX set on the channel will not be applied to the data.
 /// </para>
 /// <para>
 /// When queued encoding is enabled via the <see cref="EncodeFlags.Queue"/> flag, the DSP system or <see cref="EncodeWrite(int,IntPtr,int)" /> call will just buffer the data, and the data will then be fed to the encoder by another thread.
 /// The buffer will grow as needed to hold the queued data, up to a limit specified by the <see cref="Queue"/> config option.
 /// If the limit is exceeded (or there is no free memory), data will be lost;
 /// <see cref="EncodeSetNotify" /> can be used to be notified of that occurrence.
 /// The amount of data that is currently queued, as well as the queue limit and how much data has been lost, is available from <see cref="EncodeGetCount" />.
 /// </para>
 /// <para>When done encoding, use <see cref="EncodeStop(int)" /> or <see cref="EncodeStop(int,bool)" /> to close the encoder.</para>
 /// <para>
 /// Multiple encoders can be set on a channel.
 /// For convenience, most of the encoder functions will accept either an encoder handle or a channel handle.
 /// When a channel handle is used, the function is applied to all encoders that are set on that channel.
 /// </para>
 /// </remarks>
 /// <exception cref="Errors.Handle"><paramref name="Handle" /> is not valid.</exception>
 /// <exception cref="Errors.Create">The file could not be created.</exception>
 /// <exception cref="Errors.Unknown">Some other mystery problem!</exception>
 public static int EncodeStart(int Handle, string Filename, EncodeFlags Flags, EncoderProcedure Procedure, IntPtr User = default(IntPtr))
 {
     return(BASS_Encode_StartUser(Handle, Filename, Flags | EncodeFlags.Unicode, Procedure, User));
 }
Exemple #18
0
 /// <summary>
 /// Sets up an encoder on a channel, using an ACM codec and writing the output to a file.
 /// </summary>
 /// <param name="Handle">The channel handle... a HSTREAM, HMUSIC, or HRECORD.</param>
 /// <param name="Format">ACM codec output format (as returned by <see cref="GetACMFormat" />).</param>
 /// <param name="Flags">A combination of <see cref="EncodeFlags"/>.</param>
 /// <param name="FileName">The filename to write.</param>
 /// <returns>The encoder handle is returned if the encoder is successfully started, else 0 is returned. Use <see cref="Bass.LastError" /> to get the error code.</returns>
 /// <remarks>
 /// The ACM encoder allows installed ACM (Audio Compression Manager) codecs to be used for encoding.
 /// The codec used is determined by the contents of the Format parameter.
 /// The <see cref="GetACMFormat" /> function can be used to initialize that.
 /// <para>
 /// Internally, the sending of sample data to the encoder is implemented via a DSP callback on the channel.
 /// That means when you play the channel (or call <see cref="Bass.ChannelGetData(int,IntPtr,int)" /> if it's a decoding channel), the sample data will be sent to the encoder at the same time.
 /// The encoding is performed in the DSP callback.
 /// There isn't a separate process doing the encoding, as when using an external encoder via <see cref="EncodeStart(int,string,EncodeFlags,EncodeProcedure,IntPtr)" />.
 /// </para>
 /// <para>
 /// By default, the encoder DSP has a priority setting of -1000, which determines where in the DSP chain the encoding is performed.
 /// That can be changed using the <see cref="DSPPriority"/> config option.
 /// </para>
 /// <para>
 /// Besides the automatic DSP system, data can also be manually fed to the encoder via the <see cref="EncodeWrite(int,IntPtr,int)" /> function.
 /// Both methods can be used together, but in general, the "automatic" system ought be paused when using the "manual" system, by use of the <see cref="EncodeFlags.Pause"/> flag or the <see cref="EncodeSetPaused" /> function.
 /// </para>
 /// <para>
 /// When queued encoding is enabled via the <see cref="EncodeFlags.Queue"/> flag, the DSP system or <see cref="EncodeWrite(int,IntPtr,int)" /> call will just buffer the data, and the data will then be fed to the encoder by another thread.
 /// The buffer will grow as needed to hold the queued data, up to a limit specified by the <see cref="EncodeFlags.Queue"/> config option.
 /// If the limit is exceeded (or there is no free memory), data will be lost;
 /// <see cref="EncodeSetNotify" /> can be used to be notified of that occurrence.
 /// The amount of data that is currently queued, as well as the queue limit and how much data has been lost, is available from <see cref="EncodeGetCount" />.
 /// </para>
 /// <para>When done encoding, use <see cref="EncodeStop(int)" /> to close the encoder.</para>
 /// <para>
 /// Multiple encoders can be set on a channel.
 /// For simplicity, the encoder functions will accept either an encoder handle or a channel handle.
 /// When using a channel handle, the function is applied to all encoders that are set on that channel.
 /// </para>
 /// </remarks>
 /// <exception cref="Errors.Handle"><paramref name="Handle" /> is not valid.</exception>
 /// <exception cref="Errors.NotAvailable">The codec specified in <paramref name="Format" /> couldn't be initialized.</exception>
 /// <exception cref="Errors.Create">The file couldn't be created.</exception>
 /// <exception cref="Errors.Unknown">Some other mystery problem!</exception>
 public static int EncodeStartACM(int Handle, IntPtr Format, EncodeFlags Flags, string FileName)
 {
     return(BASS_Encode_StartACMFile(Handle, Format, Flags | EncodeFlags.Unicode, FileName));
 }
        internal const int MaxLineLength    = 72; // Used when breaking text blocks, don't use any value greater than 72... it will not work in some clients (outlook 2007)

        private static int QP_CalcSize(System.Text.Encoding encoding, byte[] buffer, EncodeFlags flags)
        {
            string heading      = "=?" + encoding.HeaderName + "?Q?";
            string terminator   = "?=";
            string lwsp         = "\r\n\t"; // linear-white-space
            bool   isSingleLine = (flags & EncodeFlags.SingleLine) == EncodeFlags.SingleLine;
            int    encodedcount = 0;
            sbyte  cur;

            encodedcount += heading.Length;
            for (int x = 0; x < buffer.Length; x++)
            {
                cur = (sbyte)buffer[x];
                //is this a valid ascii character?
                bool processed = false;
                bool doit      = false;
                if (((cur >= 33) && (cur <= 60)) || ((cur >= 62) && (cur <= 126)) || (cur == '\r') || (cur == '\n') || (cur == '\t') || (cur == ' '))
                {
                    if ((cur == '\r') || (cur == '\n'))
                    {
                        // When encoding a single line field escape the newline chars
                        if ((flags & EncodeFlags.MultiLine) == EncodeFlags.MultiLine)
                        {
                            doit = true;
                        }
                    }
                    else if (cur == 63)     // '?'
                    // We must escape this char as it is not allowed
                    {
                        doit = false;
                    }
                    else if ((cur == ' ') || (cur == '\t'))     // '?'
                    // We must escape these chars as it is not allowed
                    {
                        doit = false;
                    }
                    else
                    {
                        doit = true;
                    }
                    if (doit)
                    {
                        if (!isSingleLine && encodedcount + 2 + 1 > MaxEncodedLength)   // 2 for the terminator, 1 for the char
                        {
                            encodedcount += terminator.Length;
                            encodedcount += lwsp.Length;
                            encodedcount += heading.Length;
                        }
                        encodedcount++;
                        processed = true;
                    }
                }
                if (!processed)
                {
                    if (!isSingleLine && encodedcount + 2 + 3 > MaxEncodedLength)   // 2 for the terminator, 3 for the chars
                    {
                        encodedcount += terminator.Length;
                        encodedcount += lwsp.Length;
                        encodedcount += heading.Length;
                    }
                    encodedcount += 3;
                }
            }
            return(encodedcount);
        }
Exemple #20
0
 /// <summary>
 /// Start FLAC Encoding to <see cref="EncodeProcedure"/>.
 /// </summary>
 public static int Start(int Handle, string Options, EncodeFlags Flags, EncodeProcedureEx ProcedureEx, IntPtr User)
 {
     return BASS_Encode_FLAC_Start(Handle, Options, Flags | EncodeFlags.Unicode, ProcedureEx, User);
 }
 // Receives a string and returns true if the string contains chars that are not plain letters, numbers or a white space.
 internal static bool NeedsEncoding(System.Text.Encoding encoding, string text, EncodeFlags flags)
 {
     for (int i = 0; i < text.Length; i++)
     {
         if ((text[i] != 32) && ((text[i] < 48) || (text[i] > 57)) && ((text[i] < 65) || (text[i] > 90)) && ((text[i] < 97) || (text[i] > 122)))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #22
0
 public static extern int EncodeStartCA(int Handle, int ftype, int atype, EncodeFlags Flags, int Bitrate, EncodeProcedureEx Procedure, IntPtr User);
Exemple #23
0
 static extern int BASS_Encode_StartCAFile(int Handle, int ftype, int atype, EncodeFlags flags, int bitrate, string filename);
Exemple #24
0
 /// <summary>
 /// Sets up an encoder on a channel, using a CoreAudio codec and sending the output to a user defined function (iOS and Mac).
 /// </summary>
 /// <param name="Handle">The channel handle... a HSTREAM, HMUSIC, or HRECORD.</param>
 /// <param name="ftype">File format identifier.</param>
 /// <param name="atype">Audio data format identifier</param>
 /// <param name="Flags">A combination of <see cref="EncodeFlags"/>.</param>
 /// <param name="Bitrate">The bitrate in bits per second... 0 = the codec's default bitrate.</param>
 /// <param name="Filename">The output filename.</param>
 /// <returns>The encoder handle is returned if the encoder is successfully started, else 0 is returned. Use <see cref="Bass.LastError"/> to get the error code.</returns>
 /// <remarks>
 /// This function allows CoreAudio codecs to be used for encoding.
 /// The available file and audio data identifiers, as well as other information, can be retreived via the Audio File Services and Audio Format Services APIs, eg. the kAudioFileGlobalInfo_WritableTypes and kAudioFormatProperty_EncodeFormatIDs properties.
 /// <para>
 /// Internally, the sending of sample data to the encoder is implemented via a DSP callback on the channel.
 /// That means when you play the channel (or call <see cref="Bass.ChannelGetData(int,IntPtr,int)" /> if it's a decoding channel), the sample data will be sent to the encoder at the same time.
 /// It also means that if you use the <see cref="Bass.FloatingPointDSP"/> option, then the sample data will be 32-bit floating-point, and you'll need to use one of the Floating-point flags if the encoder does not support floating-point sample data.
 /// The <see cref="Bass.FloatingPointDSP"/> setting should not be changed while encoding is in progress.
 /// </para>
 /// <para>The encoder DSP has a priority setting of -1000, so if you want to set DSP/FX on the channel and have them present in the encoding, set their priority above that.</para>
 /// <para>
 /// Besides the automatic DSP system, data can also be manually fed to the encoder via the <see cref="EncodeWrite(int,IntPtr,int)" /> function.
 /// Both methods can be used together, but in general, the "automatic" system ought be paused when using the "manual" system, by use of the <see cref="EncodeFlags.Pause"/> flag or the <see cref="EncodeSetPaused" /> function.
 /// </para>
 /// <para>
 /// When queued encoding is enabled via the <see cref="EncodeFlags.Queue"/> flag, the DSP system or <see cref="EncodeWrite(int,IntPtr,int)" /> call will just buffer the data, and the data will then be fed to the encoder by another thread.
 /// The buffer will grow as needed to hold the queued data, up to a limit specified by the <see cref="Queue"/> config option.
 /// If the limit is exceeded (or there is no free memory), data will be lost; <see cref="EncodeSetNotify(int,EncodeNotifyProcedure,IntPtr)" /> can be used to be notified of that occurrence.
 /// The amount of data that is currently queued, as well as the queue limit and how much data has been lost, is available from <see cref="EncodeGetCount(int,EncodeCount)" />.
 /// </para>
 /// <para>
 /// <see cref="EncodeIsActive" /> can be used to check that the encoder is still running.
 /// When done encoding, use <see cref="EncodeStop(int)" /> to close the encoder.
 /// </para>
 /// <para>The returned process Handle can be used to do things like change the encoder's priority and get it's exit code.</para>
 /// <para>
 /// Multiple encoders can be set on a channel.
 /// For simplicity, the encoder functions will accept either an encoder Handle or a channel Handle.
 /// When using a channel Handle, the function is applied to all encoders that are set on that channel.
 /// </para>
 /// <para><b>Platform-specific</b></para>
 /// <para>This function is only available on OSX and iOS.</para>
 /// </remarks>
 /// <exception cref="Errors.Handle"><paramref name="Handle"/> is not valid.</exception>
 /// <exception cref="Errors.FileFormat"><paramref name="ftype"/> is not valid.</exception>
 /// <exception cref="Errors.Codec"><paramref name="atype"/> is not valid.</exception>
 /// <exception cref="Errors.NotAvailable"><paramref name="Bitrate"/> is not supported by the codec.</exception>
 /// <exception cref="Errors.SampleFormat">The channel's sample format is not supported by the codec.</exception>
 /// <exception cref="Errors.Create">The file could not be created.</exception>
 /// <exception cref="Errors.Unknown">Some other mystery problem!</exception>
 public static int EncodeStartCA(int Handle, int ftype, int atype, EncodeFlags Flags, int Bitrate, string Filename)
 {
     return(BASS_Encode_StartCAFile(Handle, ftype, atype, Flags | EncodeFlags.Unicode, Bitrate, Filename));
 }
Exemple #25
0
 /// <summary>
 /// Start Ogg Encoding to <see cref="EncodeProcedure"/>.
 /// </summary>
 /// <param name="Handle">The channel handle... a HSTREAM, HMUSIC, or HRECORD.</param>
 /// <param name="Options">
 /// Encoder options... null = use defaults.
 /// The following OGGENC style options are supported: -b / --bitrate, -m / --min-bitrate, -M / --max-bitrate, -q / --quality, -s / --serial, -t / --title, -a / --artist, -G / --genre, -d / --date, -l / --album, -N / --tracknum, -c / --comment.
 /// Anything else that is included will be ignored.
 /// </param>
 /// <param name="Flags">A combination of <see cref="EncodeFlags"/>.</param>
 /// <param name="Procedure">Optional callback function to receive the encoded data... null = no callback.</param>
 /// <param name="User">User instance data to pass to the callback function.</param>
 /// <returns>The encoder handle is returned if the encoder is successfully started, else 0 is returned. Use <see cref="Bass.LastError"/> to get the error code</returns>
 /// <remarks>
 /// <see cref="BassEnc.EncodeStart(int,string,EncodeFlags,EncoderProcedure,IntPtr)"/> is used internally to apply the encoder to the source channel, so the remarks in its documentation also apply to this function.
 ///
 /// <b>Platform-specific</b>
 /// Ogg Vorbis encoding involves extensive floating-point operations, so it is not supported on platforms/architectures that do not have an FPU, eg. older ARM platforms/architectures.
 /// </remarks>
 /// <exception cref="Errors.Handle"><paramref name="Handle"/> is not valid</exception>
 /// <exception cref="Errors.SampleFormat">The channel's sample format is not supported by the encoder.</exception>
 /// <exception cref="Errors.NotAvailable">This function is not available on platforms/architectures without an FPU.</exception>
 /// <exception cref="Errors.Unknown">Some other mystery problem! </exception>
 public static int Start(int Handle, string Options, EncodeFlags Flags, EncodeProcedure Procedure, IntPtr User)
 {
     return(BASS_Encode_OGG_Start(Handle, Options, Flags | EncodeFlags.Unicode, Procedure, User));
 }
Exemple #26
0
 static extern int BASS_Encode_StartLimit(int handle, string cmdline, EncodeFlags flags, EncodeProcedure proc, IntPtr user, int limit);
Exemple #27
0
 /// <summary>
 /// Start Ogg Encoding to File.
 /// </summary>
 /// <param name="Handle">The channel handle... a HSTREAM, HMUSIC, or HRECORD.</param>
 /// <param name="Options">
 /// Encoder options... null = use defaults.
 /// The following OGGENC style options are supported: -b / --bitrate, -m / --min-bitrate, -M / --max-bitrate, -q / --quality, -s / --serial, -t / --title, -a / --artist, -G / --genre, -d / --date, -l / --album, -N / --tracknum, -c / --comment.
 /// Anything else that is included will be ignored.
 /// </param>
 /// <param name="Flags">A combination of <see cref="EncodeFlags"/>.</param>
 /// <param name="FileName">Output filename... null = no output file.</param>
 /// <returns>The encoder handle is returned if the encoder is successfully started, else 0 is returned. Use <see cref="Bass.LastError"/> to get the error code</returns>
 /// <remarks>
 /// <see cref="BassEnc.EncodeStart(int,string,EncodeFlags,EncoderProcedure,IntPtr)"/> is used internally to apply the encoder to the source channel, so the remarks in its documentation also apply to this function.
 ///
 /// <b>Platform-specific</b>
 /// Ogg Vorbis encoding involves extensive floating-point operations, so it is not supported on platforms/architectures that do not have an FPU, eg. older ARM platforms/architectures.
 /// </remarks>
 /// <exception cref="Errors.Handle"><paramref name="Handle"/> is not valid</exception>
 /// <exception cref="Errors.SampleFormat">The channel's sample format is not supported by the encoder.</exception>
 /// <exception cref="Errors.Create">The file could not be created.</exception>
 /// <exception cref="Errors.NotAvailable">This function is not available on platforms/architectures without an FPU.</exception>
 /// <exception cref="Errors.Unknown">Some other mystery problem! </exception>
 public static int Start(int Handle, string Options, EncodeFlags Flags, string FileName)
 {
     return(BASS_Encode_OGG_StartFile(Handle, Options, Flags | EncodeFlags.Unicode, FileName));
 }
Exemple #28
0
 public static extern int EncodeStart(int handle, [MarshalAs(UnmanagedType.LPStr)] string cmdline, EncodeFlags flags, EncodeProcedure proc, IntPtr user);