Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 674... Línea 674...
674
                $ccache->open($this->prefs['gssapi_cn']);
674
                $ccache->open($this->prefs['gssapi_cn']);
675
                $gssapicontext = new GSSAPIContext();
675
                $gssapicontext = new GSSAPIContext();
676
                $gssapicontext->acquireCredentials($ccache);
676
                $gssapicontext->acquireCredentials($ccache);
Línea 677... Línea 677...
677
 
677
 
678
                $token   = '';
678
                $token   = '';
679
                $success = $gssapicontext->initSecContext($this->prefs['gssapi_context'], null, null, null, $token);
679
                $success = $gssapicontext->initSecContext($this->prefs['gssapi_context'], '', 0, 0, $token);
680
                $token   = base64_encode($token);
680
                $token   = base64_encode($token);
681
            }
681
            }
682
            catch (Exception $e) {
682
            catch (Exception $e) {
683
                trigger_error($e->getMessage(), E_USER_WARNING);
683
                trigger_error($e->getMessage(), E_USER_WARNING);
Línea 1052... Línea 1052...
1052
            $_host = ($ssl_mode == 'tls' ? 'tls://' : '') . $host . ':' . $port;
1052
            $_host = ($ssl_mode == 'tls' ? 'tls://' : '') . $host . ':' . $port;
1053
            $this->debug("Connecting to $_host...");
1053
            $this->debug("Connecting to $_host...");
1054
        }
1054
        }
Línea 1055... Línea 1055...
1055
 
1055
 
1056
        if (!empty($this->prefs['socket_options'])) {
1056
        if (!empty($this->prefs['socket_options'])) {
1057
            $options  = array_intersect_key($this->prefs['socket_options'], ['ssl' => 1]);
1057
            $options = array_intersect_key($this->prefs['socket_options'], ['ssl' => 1, 'socket' => 1]);
1058
            $context  = stream_context_create($options);
1058
            $context = stream_context_create($options);
1059
            $this->fp = stream_socket_client($host . ':' . $port, $errno, $errstr,
1059
            $this->fp = stream_socket_client($host . ':' . $port, $errno, $errstr,
1060
                $this->prefs['timeout'], STREAM_CLIENT_CONNECT, $context);
1060
                $this->prefs['timeout'], STREAM_CLIENT_CONNECT, $context);
1061
        }
1061
        }
1062
        else {
1062
        else {
Línea 2518... Línea 2518...
2518
 
2518
 
2519
                $result[$id]            = new rcube_message_header;
2519
                $result[$id]            = new rcube_message_header;
2520
                $result[$id]->id        = $id;
2520
                $result[$id]->id        = $id;
2521
                $result[$id]->subject   = '';
2521
                $result[$id]->subject   = '';
-
 
2522
                $result[$id]->messageID = 'mid:' . $id;
Línea 2522... Línea 2523...
2522
                $result[$id]->messageID = 'mid:' . $id;
2523
                $result[$id]->folder = $mailbox;
2523
 
2524
 
Línea 2524... Línea 2525...
2524
                $headers = null;
2525
                $headers = null;
Línea 2549... Línea 2550...
2549
 
2550
 
2550
                                $result[$id]->flags[$flag] = true;
2551
                                $result[$id]->flags[$flag] = true;
2551
                            }
2552
                            }
2552
                        }
2553
                        }
-
 
2554
                    }
-
 
2555
                    else if ($name == 'ANNOTATION') {
-
 
2556
                        $result[$id]->annotations = [];
-
 
2557
                        if (!empty($value) && is_array($value)) {
-
 
2558
                            $n = 0;
-
 
2559
                            while (!empty($value[$n]) && is_string($value[$n])) {
-
 
2560
                                $name = $value[$n++];
-
 
2561
                                $list = $value[$n++];
-
 
2562
                                $result[$id]->annotations[$name] = [];
-
 
2563
                                $c = 0;
-
 
2564
                                while (!empty($list[$c]) && is_string($list[$c])) {
-
 
2565
                                    $result[$id]->annotations[$name][$list[$c++]] = $list[$c++];
-
 
2566
                                }
-
 
2567
                            }
-
 
2568
                        }
2553
                    }
2569
                    }
2554
                    else if ($name == 'MODSEQ') {
2570
                    else if ($name == 'MODSEQ') {
2555
                        $result[$id]->modseq = $value[0];
2571
                        $result[$id]->modseq = $value[0];
2556
                    }
2572
                    }
2557
                    else if ($name == 'ENVELOPE') {
2573
                    else if ($name == 'ENVELOPE') {
Línea 2684... Línea 2700...
2684
     *
2700
     *
2685
     * @param string $mailbox     Mailbox name
2701
     * @param string $mailbox     Mailbox name
2686
     * @param mixed  $message_set Message(s) sequence identifier(s) or UID(s)
2702
     * @param mixed  $message_set Message(s) sequence identifier(s) or UID(s)
2687
     * @param bool   $is_uid      True if $message_set contains UIDs
2703
     * @param bool   $is_uid      True if $message_set contains UIDs
2688
     * @param bool   $bodystr     Enable to add BODYSTRUCTURE data to the result
2704
     * @param bool   $bodystr     Enable to add BODYSTRUCTURE data to the result
2689
     * @param array  $add_headers List of additional headers
2705
     * @param array  $add_headers List of additional headers to fetch
-
 
2706
     * @param array  $query_items List of additional items to fetch
2690
     *
2707
     *
2691
     * @return bool|array List of rcube_message_header elements, False on error
2708
     * @return bool|array List of rcube_message_header elements, False on error
2692
     */
2709
     */
2693
    public function fetchHeaders($mailbox, $message_set, $is_uid = false, $bodystr = false, $add_headers = [])
2710
    public function fetchHeaders($mailbox, $message_set, $is_uid = false, $bodystr = false, $add_headers = [], $query_items = [])
2694
    {
2711
    {
2695
        $query_items = ['UID', 'RFC822.SIZE', 'FLAGS', 'INTERNALDATE'];
2712
        $query_items = array_unique(array_merge($query_items, ['UID', 'RFC822.SIZE', 'FLAGS', 'INTERNALDATE']));
2696
        $headers     = ['DATE', 'FROM', 'TO', 'SUBJECT', 'CONTENT-TYPE', 'CC', 'REPLY-TO',
2713
        $headers = ['DATE', 'FROM', 'TO', 'SUBJECT', 'CONTENT-TYPE', 'CC', 'REPLY-TO',
2697
            'LIST-POST', 'DISPOSITION-NOTIFICATION-TO', 'X-PRIORITY'];
2714
            'LIST-POST', 'DISPOSITION-NOTIFICATION-TO', 'X-PRIORITY'];
Línea 2698... Línea 2715...
2698
 
2715
 
2699
        if (!empty($add_headers)) {
2716
        if (!empty($add_headers)) {
2700
            $add_headers = array_map('strtoupper', $add_headers);
2717
            $add_headers = array_map('strtoupper', $add_headers);
Línea 2716... Línea 2733...
2716
     * @param string $mailbox     Mailbox name
2733
     * @param string $mailbox     Mailbox name
2717
     * @param int    $id          Message sequence identifier or UID
2734
     * @param int    $id          Message sequence identifier or UID
2718
     * @param bool   $is_uid      True if $id is an UID
2735
     * @param bool   $is_uid      True if $id is an UID
2719
     * @param bool   $bodystr     Enable to add BODYSTRUCTURE data to the result
2736
     * @param bool   $bodystr     Enable to add BODYSTRUCTURE data to the result
2720
     * @param array  $add_headers List of additional headers
2737
     * @param array  $add_headers List of additional headers
-
 
2738
     * @param array  $query_items List of additional items to fetch
2721
     *
2739
     *
2722
     * @return bool|rcube_message_header Message data, False on error
2740
     * @return bool|rcube_message_header Message data, False on error
2723
     */
2741
     */
2724
    public function fetchHeader($mailbox, $id, $is_uid = false, $bodystr = false, $add_headers = [])
2742
    public function fetchHeader($mailbox, $id, $is_uid = false, $bodystr = false, $add_headers = [], $query_items = [])
2725
    {
2743
    {
2726
        $a = $this->fetchHeaders($mailbox, $id, $is_uid, $bodystr, $add_headers);
2744
        $a = $this->fetchHeaders($mailbox, $id, $is_uid, $bodystr, $add_headers, $query_items);
Línea 2727... Línea 2745...
2727
 
2745
 
2728
        if (is_array($a)) {
2746
        if (is_array($a)) {
2729
            return array_shift($a);
2747
            return array_shift($a);
Línea 2953... Línea 2971...
2953
                    $line = trim($this->readLine(1024)); // the OK response line
2971
                    $line = trim($this->readLine(1024)); // the OK response line
2954
                    continue;
2972
                    continue;
2955
                }
2973
                }
Línea 2956... Línea 2974...
2956
 
2974
 
2957
                if ($result !== false) {
2975
                if ($result !== false) {
2958
                    $result = $this->decodeContent($result, $mode, true);
2976
                    $result = $this->decodeContent($result, $mode, true, $prev, $formatted);
2959
                }
2977
                }
2960
            }
2978
            }
2961
            // response with string literal
2979
            // response with string literal
2962
            else if (preg_match('/\{([0-9]+)\}$/', $line, $m)) {
2980
            else if (preg_match('/\{([0-9]+)\}$/', $line, $m)) {
Línea 2986... Línea 3004...
2986
                        $chunk = substr($chunk, 0, $bytes);
3004
                        $chunk = substr($chunk, 0, $bytes);
2987
                        $len = strlen($chunk);
3005
                        $len = strlen($chunk);
2988
                    }
3006
                    }
2989
                    $bytes -= $len;
3007
                    $bytes -= $len;
Línea 2990... Línea 3008...
2990
 
3008
 
Línea 2991... Línea 3009...
2991
                    $chunk = $this->decodeContent($chunk, $mode, $bytes <= 0, $prev);
3009
                    $chunk = $this->decodeContent($chunk, $mode, $bytes <= 0, $prev, $formatted);
2992
 
3010
 
2993
                    if ($file) {
3011
                    if ($file) {
2994
                        if (fwrite($file, $chunk) === false) {
3012
                        if (fwrite($file, $chunk) === false) {
Línea 3022... Línea 3040...
3022
    }
3040
    }
Línea 3023... Línea 3041...
3023
 
3041
 
3024
    /**
3042
    /**
3025
     * Decodes a chunk of a message part content from a FETCH response.
3043
     * Decodes a chunk of a message part content from a FETCH response.
3026
     *
3044
     *
3027
     * @param string $chunk   Content
3045
     * @param string $chunk     Content
3028
     * @param int    $mode    Encoding mode
3046
     * @param int    $mode      Encoding mode
3029
     * @param bool   $is_last Whether it is a last chunk of data
3047
     * @param bool   $is_last   Whether it is a last chunk of data
-
 
3048
     * @param string $prev      Extra content from the previous chunk
3030
     * @param string $prev    Extra content from the previous chunk
3049
     * @param bool   $formatted Format the content for output
3031
     *
3050
     *
3032
     * @return string Encoded string
3051
     * @return string Encoded string
3033
     */
3052
     */
3034
    protected static function decodeContent($chunk, $mode, $is_last = false, &$prev = '')
3053
    protected static function decodeContent($chunk, $mode, $is_last = false, &$prev = '', $formatted = false)
3035
    {
3054
    {
3036
        // BASE64
3055
        // BASE64
3037
        if ($mode == 1) {
3056
        if ($mode == 1) {
Línea 3047... Línea 3066...
3047
            }
3066
            }
3048
            else {
3067
            else {
3049
                $prev = '';
3068
                $prev = '';
3050
            }
3069
            }
Línea -... Línea 3070...
-
 
3070
 
-
 
3071
            // There might be multiple base64 blocks in a single message part,
-
 
3072
            // we have to pass them separately to base64_decode() (#9290)
-
 
3073
            $result = '';
3051
 
3074
            foreach (preg_split('|=+|', $chunk, -1, \PREG_SPLIT_NO_EMPTY) as $_chunk) {
3052
            return base64_decode($chunk);
3075
                $result .= base64_decode($_chunk);
Línea -... Línea 3076...
-
 
3076
            }
-
 
3077
 
3053
        }
3078
            $chunk = $result;
3054
 
3079
        }
3055
        // QUOTED-PRINTABLE
3080
        // QUOTED-PRINTABLE
3056
        if ($mode == 2) {
3081
        elseif ($mode == 2) {
3057
            if (!self::decodeContentChunk($chunk, $prev, $is_last)) {
3082
            if (!self::decodeContentChunk($chunk, $prev, $is_last)) {
Línea 3058... Línea -...
3058
                return '';
-
 
3059
            }
-
 
3060
 
3083
                return '';
3061
            $chunk = preg_replace('/[\t\r\0\x0B]+\n/', "\n", $chunk);
3084
            }
3062
 
-
 
3063
            return quoted_printable_decode($chunk);
3085
 
3064
        }
3086
            $chunk = quoted_printable_decode($chunk);
3065
 
3087
        }
3066
        // X-UUENCODE
3088
        // X-UUENCODE
3067
        if ($mode == 3) {
3089
        elseif ($mode == 3) {
Línea 3068... Línea 3090...
3068
            if (!self::decodeContentChunk($chunk, $prev, $is_last)) {
3090
            if (!self::decodeContentChunk($chunk, $prev, $is_last)) {
Línea 3077... Línea 3099...
3077
 
3099
 
3078
            if (!strlen($chunk)) {
3100
            if (!strlen($chunk)) {
3079
                return '';
3101
                return '';
Línea 3080... Línea 3102...
3080
            }
3102
            }
3081
 
3103
 
3082
            return convert_uudecode($chunk);
-
 
3083
        }
3104
            $chunk = convert_uudecode($chunk);
3084
 
3105
        }
3085
        // Plain text formatted
3106
        // Plain text formatted
3086
        // TODO: Formatting should be handled outside of this class
3107
        // TODO: Formatting should be handled outside of this class
3087
        if ($mode == 4) {
3108
        elseif ($mode == 4) {
3088
            if (!self::decodeContentChunk($chunk, $prev, $is_last)) {
3109
            if (!self::decodeContentChunk($chunk, $prev, $is_last)) {
Línea 3089... Línea 3110...
3089
                return '';
3110
                return '';
3090
            }
3111
            }
3091
 
3112
 
-
 
3113
            if ($is_last) {
Línea -... Línea 3114...
-
 
3114
                $chunk = rtrim($chunk, "\t\r\n\0\x0B");
3092
            if ($is_last) {
3115
            }
3093
                $chunk = rtrim($chunk, "\t\r\n\0\x0B");
3116
        }
Línea 3094... Línea 3117...
3094
            }
3117
 
3095
 
3118
        if ($formatted) {
Línea 3743... Línea 3766...
3743
            return $result;
3766
            return $result;
3744
        }
3767
        }
3745
    }
3768
    }
Línea 3746... Línea 3769...
3746
 
3769
 
-
 
3770
    /**
-
 
3771
     * Send the STORE X ANNOTATION command (RFC5257)
-
 
3772
     *
-
 
3773
     * @param string $mailbox Mailbox name
-
 
3774
     * @param array  $entries
-
 
3775
     *
-
 
3776
     * @return bool True on success, False on failure
-
 
3777
     *
-
 
3778
     * @since 1.6.10
-
 
3779
     */
-
 
3780
    public function storeMessageAnnotation($mailbox, $uids, $entries)
-
 
3781
    {
-
 
3782
        if (!$this->hasCapability('ANNOTATE-EXPERIMENT-1')) {
-
 
3783
            return false;
-
 
3784
        }
-
 
3785
 
-
 
3786
        if (empty($entries) || empty($uids)) {
-
 
3787
            $this->setError(self::ERROR_COMMAND, 'Wrong argument for STORE ANNOTATION command');
-
 
3788
            return false;
-
 
3789
        }
-
 
3790
 
-
 
3791
        if (!$this->select($mailbox)) {
-
 
3792
            return false;
-
 
3793
        }
-
 
3794
 
-
 
3795
        /* Example input compatible with rcube_message_header::$annotations:
-
 
3796
           $entries = [
-
 
3797
               '/comment' => [
-
 
3798
                   'value.priv' => 'test1',
-
 
3799
                   'value.shared' => null,
-
 
3800
               ],
-
 
3801
           ];
-
 
3802
        */
-
 
3803
 
-
 
3804
        $request = [];
-
 
3805
        foreach ($entries as $name => $annotation) {
-
 
3806
            if (!empty($annotation)) {
-
 
3807
                foreach ($annotation as $key => $value) {
-
 
3808
                    $annotation[$key] = $this->escape($key) . ' ' . $this->escape($value, true);
-
 
3809
                }
-
 
3810
                $request[] = $this->escape($name);
-
 
3811
                $request[] = $annotation;
-
 
3812
            }
-
 
3813
        }
-
 
3814
 
-
 
3815
        $result = $this->execute(
-
 
3816
            'UID STORE',
-
 
3817
            [$this->compressMessageSet($uids), 'ANNOTATION', $request],
-
 
3818
            self::COMMAND_NORESPONSE
-
 
3819
        );
-
 
3820
 
-
 
3821
        return $result == self::ERROR_OK;
-
 
3822
    }
-
 
3823
 
3747
    /**
3824
    /**
3748
     * Returns BODYSTRUCTURE for the specified message.
3825
     * Returns BODYSTRUCTURE for the specified message.
3749
     *
3826
     *
3750
     * @param string $mailbox Folder name
3827
     * @param string $mailbox Folder name
3751
     * @param int    $id      Message sequence number or UID
3828
     * @param int    $id      Message sequence number or UID