imap_base64 () problem ? :/

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    imap_base64 () problem ? :/

    I have set up a simple email script to enable all users of my site to have there own emails sent to there inbox as normal messages ....
    it works well apart from on some emails are coming through as base64 encrypted

    my question is .... how can i tell which messages to use: imap_base64() and which ones not to?

    im guessing on exploding the string by " " (space) and then counting the chars used ..... this is ok apart from if it a very small email like: eWVz

    #2
    always getting same chars??

    Comment


      #3
      hmmm maybe:
      PHP Code:
      if(imap_base64 ($text))
      {
       
      $text imap_base64 ($text);
      }
      else
      {
      /// normal

      lol going to try it

      Comment


        #4
        Originally posted by something else View Post
        I have set up a simple email script to enable all users of my site to have there own emails sent to there inbox as normal messages ....
        it works well apart from on some emails are coming through as base64 encrypted

        my question is .... how can i tell which messages to use: imap_base64() and which ones not to?

        im guessing on exploding the string by " " (space) and then counting the chars used ..... this is ok apart from if it a very small email like: eWVz
        php[net]

        Looks like this function has exactly the same behavior as base64_decode($test, true) -> it returns FALSE if $text contains characters outside the Base64 alphabet, although this isn't documented here.
        This is ten percent luck, twenty percent skill
        Fifteen percent concentrated power of will
        Five percent pleasure, fifty percent pain

        And a hundred percent reason to remember the name!

        Comment


          #5
          Originally posted by just_m3. View Post
          php[net]

          Looks like this function has exactly the same behavior as base64_decode($test, true) -> it returns FALSE if $text contains characters outside the Base64 alphabet, although this isn't documented here.
          yeah all chars are inside base64 alaphabet

          and my above code didnt work :/

          Comment


            #6
            Originally posted by something else View Post
            yeah all chars are inside base64 alaphabet

            and my above code didnt work :/
            php[net] base 64

            Since I'm not able to upgrade PHP to the latest version, I needed a way to check if some data had actually been encoded before trying to decode it. Here is the function I've used; I hope it helps someone.

            PHP Code:
            <?php
              
            /**
               * Check a string of base64 encoded data to make sure it has actually
               * been encoded.
               *
               * @param $encodedString string Base64 encoded string to validate.
               * @return Boolean Returns true when the given string only contains 
               * base64 characters; returns false if there is even one non-base64 character.
               */
              
            function checkBase64Encoded($encodedString) {
                
            $length strlen($encodedString);
                
                
            // Check every character.
                
            for ($i 0$i $length; ++$i) {
                  
            $c $encodedString[$i];
                  if (
                    (
            $c '0' || $c '9')
                    && (
            $c 'a' || $c 'z')
                    && (
            $c 'A' || $c 'Z')
                    && (
            $c != '+')
                    && (
            $c != '/')
                    && (
            $c != '=')
                  ) {
                    
            // Bad character found.
                    
            return false;
                  }
                }
                
            // Only good characters found.
                
            return true;
              }
            ?>
            try with imap :D .. might work'


            fast check shorted name ...
            PHP Code:
            <?php

             
            function checkBase64($encodedString) { 
                
            $length strlen($encodedString); 
                 
                
            // Check every character. 
                
            for ($i 0$i $length; ++$i) { 
                  
            $c $encodedString[$i]; 
                  if ( 
                    (
            $c '0' || $c '9'
                    && (
            $c 'a' || $c 'z'
                    && (
            $c 'A' || $c 'Z'
                    && (
            $c != '+'
                    && (
            $c != '/'
                    && (
            $c != '='
                  ) { 
                    
            // Bad character found. 
                    
            return false
                  } 
                } 
                
            // Only good characters found. 
                
            return true
              }
              
              
            $text="ZGVtbyB0ZXh0";
            if (
            checkBase64($text)) {echo'text is encoded';} 
            else { echo
            'text is not base64 :)';}

            ?>
            Last edited by just_m3.; 18.04.12, 18:52.
            This is ten percent luck, twenty percent skill
            Fifteen percent concentrated power of will
            Five percent pleasure, fifty percent pain

            And a hundred percent reason to remember the name!

            Comment


              #7
              thankyou :D that worked .... and so did my post before (i mis-spelt $text lol)
              and so does:
              PHP Code:
              if(base64_decode($textTRUE))
              {
              //returns true
              }else{
              //false

              Comment


                #8
                Originally posted by something else View Post
                thankyou :D that worked .... and so did my post before (i mis-spelt $text lol)
                and so does:
                PHP Code:
                if(base64_decode($textTRUE))
                {
                //returns true
                }else{
                //false

                I thot you have server problems :D .. so i came up with another "solution" from php[net] ... no problem though ..

                I'm here to help ... when i can !

                Added after 5 minutes:

                Take care on your code because its not always working as tryied on local .. returns true all the time ..
                Last edited by just_m3.; 18.04.12, 19:17.
                This is ten percent luck, twenty percent skill
                Fifteen percent concentrated power of will
                Five percent pleasure, fifty percent pain

                And a hundred percent reason to remember the name!

                Comment


                  #9
                  thanks for your help that code i can use the:
                  PHP Code:
                  <?php 
                    
                  /** 
                     * Check a string of base64 encoded data to make sure it has actually 
                     * been encoded. 
                     * 
                     * @param $encodedString string Base64 encoded string to validate. 
                     * @return Boolean Returns true when the given string only contains  
                     * base64 characters; returns false if there is even one non-base64 character. 
                     */ 
                    
                  function checkBase64Encoded($encodedString) { 
                      
                  $length strlen($encodedString); 
                       
                      
                  // Check every character. 
                      
                  for ($i 0$i $length; ++$i) { 
                        
                  $c $encodedString[$i]; 
                        if ( 
                          (
                  $c '0' || $c '9'
                          && (
                  $c 'a' || $c 'z'
                          && (
                  $c 'A' || $c 'Z'
                          && (
                  $c != '+'
                          && (
                  $c != '/'
                          && (
                  $c != '='
                        ) { 
                          
                  // Bad character found. 
                          
                  return false
                        } 
                      } 
                      
                  // Only good characters found. 
                      
                  return true
                    } 
                  ?>
                  in javascript to help me detect if a string is base64 or not :D

                  Comment

                  Working...
                  X