Changeset 6122

Show
Ignore:
Timestamp:
05/31/08 20:26:24 (6 months ago)
Author:
coolengineer
Message:
  • #960
  • 허용목록(White list) 추가
  • 로그에 엔트리 링크를 추가
  • 성공한 로그는 파란색으로 보여줌
  • MMS 외에 일반 메일도 MMS로 인식할 수 있도록 함
  • 메일을 전송한 시각을 기준으로 날짜를 판단함. (기존은 메일을 확인하는 시각)
Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/components/Needlworks.Mail.Pop3.php

    r6026 r6122  
    352352            if( !isset( $mail['date'] ) && preg_match( '/^Date:\s*(.*)/i', $line, $match ) ) { 
    353353                $mail['date'] = strtotime( $match[1] ); 
    354                 $mail['date_string'] = strftime( "%Y-%m-%d %H:%M:%S", $mail['date'] ); 
    355             } 
    356             if( !isset( $mail['from'] ) && preg_match( '/^From:.*<(.*)>/i', $line, $match ) ) { 
    357                 $mail['from'] = $match[1]; 
     354                $mail['date_string'] = strftime( "%Y-%m-%d", $mail['date'] ); 
     355                $mail['time_string'] = strftime( "%H:%M:%S", $mail['date'] ); 
     356                $mail['date_year'] =   strftime( "%Y", $mail['date'] ); 
     357                $mail['date_month'] =  strftime( "%m", $mail['date'] ); 
     358                $mail['date_day'] =    strftime( "%d", $mail['date'] ); 
     359            } 
     360            if( !isset( $mail['from'] ) && preg_match( '/^From:([^<]*)<(.*)>/i', $line, $match ) ) { 
     361                $mail['sender'] = trim($this->decode_header($match[1])); 
     362                $mail['from'] = $match[2]; 
    358363            } 
    359364            if( !isset( $mail['content_transfer_encoding'] ) && preg_match( '/^Content-Transfer-Encoding:\s*(\S+)/i', $line, $match ) ) { 
  • trunk/plugins/CL_Moblog/index.php

    r6026 r6122  
    44class Moblog 
    55{ 
    6     function Moblog( $username, $password, $host, $port = 110, $ssl = 0,  
    7         $userid = 1, $minsize = 10240, $visibility = 2, $category = 0 ) 
     6    function Moblog( $options ) 
    87    { 
    98        global $pop3logs; 
     
    1110            $pop3logs = array(); 
    1211        } 
    13         $this->username = $username; 
    14         $this->password = $password; 
    15         $this->host = $host; 
    16         $this->port = $port; 
    17         $this->ssl = $ssl; 
    18         $this->userid = $userid; 
    19         $this->minsize = $minsize; 
     12        foreach( $options as $k => $v ) { 
     13            $this->$k = $v; 
     14        } 
     15 
    2016        $this->recentCount = 100; 
    21         $this->visibility = array( "private", "protected", "public", "syndicated" ); 
    22         $this->visibility = $this->visibility[$visibility]; 
    23         $this->category = $category; 
     17        $visibilities = array( "private", "protected", "public", "syndicated" ); 
     18        $this->visibility = $visibilities[$this->visibility]; 
     19        $this->allow = preg_split( "@[,\s]+@", $this->allow ) ; 
    2420 
    2521        $this->pop3 = new Pop3(); 
     
    4541    } 
    4642 
     43    function decorate_log($s) 
     44    { 
     45        global $blogURL; 
     46        $s = htmlspecialchars($s); 
     47        $s = preg_replace( "/\(SLOGAN:([^)]+)\)/", "<a href=\"$blogURL/entry/\\1\" target=\"_blank\">click</a>", $s ); 
     48        return $s; 
     49    } 
     50 
    4751    function log($msg) 
    4852    { 
     
    5256        if( $msg[0] == '*' ) { 
    5357            global $pop3logs; 
    54             array_push( $pop3logs, substr($msg,2) ); 
     58            array_push( $pop3logs, Moblog::decorate_log(substr($msg,2)) ); 
    5559        } 
    5660    } 
     
    110114    } 
    111115 
    112     function isMms( & $mail ) 
    113     { 
     116    function isAllowed( & $mail ) 
     117    { 
     118        if( isset( $mail['from'] ) && is_array( $this->allow) ) { 
     119            foreach( $this->allow as $a ) { 
     120                if( strstr( $mail['from'], $a ) !== false ) return true;  
     121                if( isset($mail['sender']) && strstr( $mail['sender'], $a ) !== false ) return true;  
     122            } 
     123        } 
     124        if( $this->allowonly ) { 
     125            $this->logMail( $mail, "SKIP, Not in ALLOW list" ); 
     126            return false; 
     127        } 
     128 
    114129        if( !empty($mail['mms']) ) { 
     130            $this->logMail( $mail, "SKIP, Not an MMS" ); 
    115131            return true; 
    116132        } 
     
    142158    } 
    143159 
     160    function logMail( $mail, $result ) 
     161    { 
     162        $date = isset( $mail['date_string'] ) ? "{$mail['date_string']} {$mail['time_string']} " : ''; 
     163        $from = isset( $mail['from'] ) ? "({$mail['sender']} <{$mail['from']}>) " : ''; 
     164        $this->log( "* "._t("메일").": {$mail['subject']} {$date} {$from}[{$result}]" ); 
     165    } 
     166 
    144167    function retrieveCallback( $lines, $uid ) 
    145168    { 
    146         $slogan = date( "Y-m-d" ); 
    147         $docid = date( "H:i:s" ); 
    148169        $this->appendUid( $uid ); 
    149170        $mail = $this->pop3->parse( $lines ); 
     171 
     172        if( isset( $mail['date_string'] ) ) { 
     173            $slogan = $mail['date_string']; 
     174            $docid = $mail['time_string']; 
     175        } else { 
     176            $slogan = date( "Y-m-d" ); 
     177            $docid = date( "H:i:s" ); 
     178        } 
    150179        if( in_array( $mail['subject'], array( '제목없음' ) ) ) { 
    151180            $mail['subject'] = ''; 
    152181        } 
    153         if( !$this->isMms($mail) ) { 
    154             $this->log( "* "._t("메일").": " . $mail['subject'] . " [SKIP]" ); 
     182        if( !$this->isAllowed($mail) ) { 
    155183            return false; 
    156184        } 
    157185        if( empty($mail['attachments']) ) { 
    158             $this->log( "* "._t("메일").": " . $mail['subject'] . " [SKIP]" ); 
     186            $this->logMail( $mail, "SKIP" ); 
    159187            return false; 
    160188        } 
     
    164192 
    165193        if( $post->open( "slogan = '$slogan'" ) ) { 
    166             $this->log( "* 기존 글을 엽니다" ); 
     194            $this->log( "* 기존 글을 엽니다. (SLOGAN:$slogan)" ); 
    167195            $post->content .= $this->_getDecoratedContent( $mail, $docid ); 
    168196            $post->modified = time(); 
    169197            $post->visibility = $this->visibility; 
    170198        } else { 
    171             $this->log( "* 새 글을 작성합니다" ); 
    172             $post->title = empty($mail['subject']) ? $slogan : $mail['subject']; 
     199            $this->log( "* 새 글을 작성합니다. (SLOGAN:$slogan)" ); 
     200            if( isset( $mail['date_year'] ) ) { 
     201                $post->title = str_replace( array('%Y','%M','%D'),  
     202                    array( $mail['date_year'], $mail['date_month'], $mail['date_day'] ), $this->subject ); 
     203            } else { 
     204                $post->title = str_replace( array('%Y','%M','%D'),  
     205                    array( date("Y"), date("m"), date("d") ), $this->subject ); 
     206            } 
    173207            $post->userid = $this->userid; 
    174208            $post->category = $this->category; 
     
    184218            $post->slogan = $slogan; 
    185219            if( !$post->add() ) { 
    186                 $this->log( "* "._t("메일").": " . $mail['subject'] . " [ERROR]" ); 
     220                $this->logMail( $mail, "ERROR" ); 
    187221                $this->log( _t("실패: 글을 추가하지 못하였습니다")." : " . $post->error ); 
    188222                return false; 
     
    204238                    ); 
    205239                if( !$att ) { 
    206                     $this->log( "* "._t("메일").": " . $mail['subject'] . " [ERROR]" ); 
     240                    $this->logMail( $mail, "ERROR" ); 
    207241                    $this->log( _t("실패: 첨부파일을 추가하지 못하였습니다")." : " . $post->error ); 
    208242                    return false; 
     
    216250            } 
    217251            if( !$post->update() ) { 
    218                 $this->log( "* "._t("메일").": " . $mail['subject'] . " [ERROR]" ); 
     252                $this->logMail( $mail, "ERROR" ); 
    219253                $this->log( _t("실패: 첨부파일을 본문에 연결하지 못하였습니다").". : " . $post->error ); 
    220254                return false; 
    221255            } 
    222256        } 
    223         $this->log( "* "._t("메일").": " . $mail['subject'] . " [OK]" ); 
     257        $this->logMail( $mail, "OK" ); 
    224258        return true; 
    225259    } 
     
    229263{ 
    230264    if( isset($_GET['check']) && $_GET['check'] == 1 ) { 
     265        echo "<html><body style=\"font-size:0.9em\">"; 
    231266        echo "<style>.emplog{color:red}.oklog{color:blue}</style>"; 
    232267        echo "<ul>"; 
     
    234269            array_map( 
    235270                create_function( '$li', 'return preg_match( "/^\S+\s+\S+\s+\*/", $li ) ?  
    236                         (preg_match( "/\[OK\]$/", $li ) ? "<li class=\"oklog\">$li</li>" : "<li class=\"emplog\">$li</li>")  
     271                        (preg_match( "/\[OK\]/", $li ) ? "<li class=\"oklog\">$li</li>" : "<li class=\"emplog\">$li</li>")  
    237272                        : "<li>$li</li>";'),  
    238                 split( "\n",file_get_contents(ROOT.DS."cache".DS."moblog.txt")) 
     273                split( "\n",Moblog::decorate_log(file_get_contents(ROOT.DS."cache".DS."moblog.txt"))) 
    239274            ) 
    240275        ); 
    241276        echo "</ul>"; 
     277        echo "</body></html>"; 
    242278        exit; 
    243279    } 
    244280 
    245     $pop3host = getBlogSetting( 'MmsPop3Host', 'localhost' ); 
    246     $pop3port = getBlogSetting( 'MmsPop3Port', 110 ); 
    247     $pop3ssl = getBlogSetting( 'MmsPop3Ssl', 0 ); 
    248     $pop3username = getBlogSetting( 'MmsPop3Username', '' ); 
    249     $pop3password = getBlogSetting( 'MmsPop3Password', '' ); 
    250     $pop3minsize = getBlogSetting( 'MmsPop3MinSize', 0 ); 
    251     $pop3category = getBlogSetting( 'MmsPop3Category', 0 ); 
    252     $pop3minsize *= 1024; 
    253     $pop3fallbackuserid = getBlogSetting( 'MmsPop3Fallbackuserid', 1 ); 
    254     $pop3visibility = getBlogSetting( 'MmsPop3Visibility', '2' ); 
    255  
    256281    header( "Content-type: text/html; charset:utf-8" ); 
    257     echo "<html><body><ul><li>"; 
    258     $moblog = new Moblog( $pop3username, $pop3password, $pop3host, $pop3port, $pop3ssl, $pop3fallbackuserid, $pop3minsize, $pop3visibility, $pop3category ); 
     282    echo '<html>'; 
     283    echo '<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />'; 
     284    echo '<body style="font-size:0.9em"><ul><li>'; 
     285    $moblog = new Moblog(  
     286        array(  
     287            'username' => getBlogSetting( 'MmsPop3Username', '' ), 
     288            'password' => getBlogSetting( 'MmsPop3Password', '' ), 
     289            'host' => getBlogSetting( 'MmsPop3Host', 'localhost' ), 
     290            'port' => getBlogSetting( 'MmsPop3Port', 110 ), 
     291            'ssl' => getBlogSetting( 'MmsPop3Ssl', 0 ), 
     292            'userid' => getBlogSetting( 'MmsPop3Fallbackuserid', 1 ), 
     293            'minsize' => getBlogSetting( 'MmsPop3MinSize', 0 )*1024, 
     294            'visibility' => getBlogSetting( 'MmsPop3Visibility', '2' ), 
     295            'category' => getBlogSetting( 'MmsPop3Category', 0 ),  
     296            'allowonly' => getBlogSetting( 'MmsPop3AllowOnly', '0' ), 
     297            'allow' => getBlogSetting( 'MmsPop3Allow', '' ), 
     298            'subject' => getBlogSetting( 'MmsPop3Subject', '%Y-%M-%D' ) )  
     299    ); 
    259300    $moblog->log( "--BEGIN--" ); 
    260301    $moblog->check(); 
     
    262303    if( Acl::check( 'group.administrators' ) ) { 
    263304        global $pop3logs; 
    264         print join("</li><li>",$pop3logs); 
    265     } 
    266     echo "</li></ul></body></html>"; 
     305        print join("</li>\n<li>",$pop3logs); 
     306    } 
     307    echo "</li>\n</ul></body></html>"; 
    267308    return true; 
    268309} 
     
    283324        setBlogSetting( 'MmsPop3Fallbackuserid', getUserId() ); 
    284325        setBlogSetting( 'MmsPop3MinSize', 0 ); 
     326        setBlogSetting( 'MmsPop3AllowOnly', !empty($_POST['pop3allowonly'])?1:0 ); 
     327        setBlogSetting( 'MmsPop3Allow', $_POST['pop3allow'] ); 
     328        setBlogSetting( 'MmsPop3Subject', $_POST['pop3subject'] ); 
    285329    } 
    286330    $pop3email = getBlogSetting( 'MmsPop3Email', '' ); 
     
    294338    $pop3fallheadercharset = getBlogSetting( 'MmsPop3Fallbackcharset', 'euc-kr' ); 
    295339    $pop3visibility = getBlogSetting( 'MmsPop3Visibility', '2' ); 
     340    $pop3mmsallowonly = getBlogSetting( 'MmsPop3AllowOnly', '0' ); 
     341    $pop3mmsallow = getBlogSetting( 'MmsPop3Allow', '' ); 
     342    $pop3subject = getBlogSetting( 'MmsPop3Subject', '%Y-%M-%D' ); 
    296343?> 
    297344                        <hr class="hidden" /> 
     
    386433                                            </dd> 
    387434                                        </dl> 
     435                                    <div class="button-box"> 
     436                                        <input type="submit" class="save-button input-button wide-button" value="<?php echo _t('저장하기');?>"  /> 
     437                                    </div> 
     438                                </div> 
     439                            <h2 class="caption"><span class="main-text"><?php echo _t('글 쓰기 환경 설정');?></span></h2> 
     440                                <div id="editor-section" class="section"> 
     441                                        <dl id="editor-line" class="line"> 
     442                                            <dt><span class="label"><?php echo _t('제목');?></span></dt> 
     443                                            <dd> 
     444                                                <input type="text" style="width:24em" class="input-text" id="pop3subject" name="pop3subject" value="<?php echo $pop3subject; ?>" /> 
     445                                                (<?php echo _t('%Y:년, %M:월, %D:일');?>) <input type="button" value="<?php echo _t("초기화");?>" onclick="document.getElementById('pop3subject').value='%Y-%M-%D';return false;" /> 
     446                                            </dd> 
     447                                        </dl> 
    388448                                        <dl id="editor-line" class="line"> 
    389449                                            <dt><span class="label"><?php echo _t('공개여부');?></span></dt> 
     
    413473                                                    </optgroup> 
    414474                                                </select> 
     475                                            </dd> 
     476                                        </dl> 
     477                                    <div class="button-box"> 
     478                                        <input type="submit" class="save-button input-button wide-button" value="<?php echo _t('저장하기');?>"  /> 
     479                                    </div> 
     480                                </div> 
     481                            <h2 class="caption"><span class="main-text"><?php echo _t('메일 필터링 설정');?></span></h2> 
     482                                <div id="editor-section" class="section"> 
     483                                        <dl id="formatter-line" class="line"> 
     484                                            <dt><span class="label"><?php echo _t('허용 목록');?></span></dt> 
     485                                            <dd> 
     486                                                <input type="radio" id="pop3allowonly" name="pop3allowonly" value="1" <?php echo $pop3mmsallowonly ? 'checked="checked"':'' ?> /> 
     487                                                <label for="pop3allowonly"><?php echo _t('다음 송신자로부터 전송된 메일만 MMS로 인식하여 처리합니다') ?></label> 
     488                                            </dd> 
     489                                            <dd> 
     490                                                <input type="radio" id="pop3allowlist" name="pop3allowonly" value="0" <?php echo $pop3mmsallowonly ? '':'checked="checked"' ?> /> 
     491                                                <label for="pop3allowlist"><?php echo _t('다음 송신자로부터 전송된 메일도 MMS로 인식하여 처리합니다'); ?></label> 
     492                                            </dd> 
     493                                            <dd> 
     494                                                <input type="text" maxlength="128" name="pop3allow" value="<?php echo htmlentities($pop3mmsallow)?>" style="width:90%" /> 
     495                                            </dd> 
     496                                            <dd> 
     497                                                <?php echo _t('여러 개인 경우 전화번호 혹은 이메일 주소를 쉼표나 공백으로 구별하여 나열합니다') ?> 
     498                                            </dd> 
     499                                            <dd> 
    415500                                            </dd> 
    416501                                        </dl> 
  • trunk/plugins/CL_Moblog/index.xml

    r6025 r6122  
    5454              </param> 
    5555              <param> 
     56                  <name>pop3allowonly</name><type>int</type><mandatory>0</mandatory> 
     57              </param> 
     58              <param> 
     59                  <name>pop3allow</name><type>string</type><mandatory>0</mandatory> 
     60              </param> 
     61              <param> 
     62                  <name>pop3subject</name><type>string</type><mandatory>0</mandatory> 
     63              </param> 
     64              <param> 
    5665                  <name>check</name><type>int</type><mandatory>0</mandatory> 
    5766              </param>