MailUtil.cs 919 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // System.Web.Mail.MailUtil.cs
  3. //
  4. // Author(s):
  5. // Per Arneng <[email protected]>
  6. //
  7. //
  8. using System;
  9. using System.Text;
  10. namespace System.Web.Mail {
  11. // This class contains some utillity functions
  12. // that doesnt fit in other classes and to keep
  13. // high cohesion on the other classes.
  14. internal class MailUtil {
  15. // determines if a string needs to
  16. // be encoded for transfering over
  17. // the smtp protocol without risking
  18. // that it would be changed.
  19. public static bool NeedEncoding( string str ) {
  20. bool needEnc = false;
  21. foreach( char chr in str ) {
  22. int ch = (int)chr;
  23. if( ! ( ( ch > 33 ) && ( ch < 61 ) ) ||
  24. ( ( ch > 61 ) && ( ch < 127 ) ) ) needEnc = true;
  25. }
  26. return needEnc;
  27. }
  28. // Encodes a string to base4
  29. public static string Base64Encode( string str ) {
  30. return Convert.ToBase64String( Encoding.Default.GetBytes( str ) );
  31. }
  32. }
  33. }