77;20202;0ccatbody - よくきたWiki

Loading ...


/**

 */

$config[ 'smtp'][ 'host'] = 'localhost';

$config[ 'smtp'][ 'port'] = 25;

$config[ 'smtp'][ 'auth'] = false;
/**

 */

$config[ 'pop3'][ 'host'] = 'localhost';

$config[ 'pop3'][ 'port'] = 110;

$config[ 'pop3'][ 'user'] = 'popuser';

$config[ 'pop3'][ 'pass'] = 'poppass';

$config[ 'pop3'][ 'apop'] = false;
/**

 */

$config[ 'mua'][ 'fromAddress'] = 'popuser@example.com';

$config[ 'mua'][ 'showList'] = 10;

$config[ 'mua'][ 'defaultDomain'] = 'example.com';

$config[ 'mua'][ 'showCharSet'] = 'euc-jp';

$config[ 'mua'][ 'mailCharSet'] = 'iso-2022-jp';

$config[ 'mua'][ 'uploadMaxSize'] = 1000000;

class cMyPop3 extends Net_POP3 {
  var $config;
   /**

   */
  function cMyPop3() {
    global $config;
    $this->config =& $config;
    parent::Net_POP3();
  }
  /**

   */
  function connect() {
    $config =& $this->config[ 'pop3'];
    return parent::connect( $config[ 'host'], $config[ 'port'], $config[ 'apop']);
  }
  /**

   */
  function login() {
    $config =& $this->config[ 'pop3'];
    return parent::login( $config[ 'user'], $config[ 'pass'], $config[ 'apop']);
  }
}
<?php
require_once 'common.inc.php';
$pop3 =& new cMyPop3;
$pop3->connect();
$pop3->login();
$list = $pop3->getListing();
$pop3->disconnect();
print_r( $list);
?>

function mail_header_join( $value, $char = ' ') {
  return is_array( $value)? implode( $char, $value): $value;
}
$headers = $pop3->getParsedHeaders( $msg_id);
$to = mail_header_join( $headers[ 'To'], ',');
/**

 */
function mb_decode_mimeheaders( $headers, $toCharSet) {
  foreach ( $headers as $name=>$value) {
    if ( is_array( $value)) {
      array_walk( $value, 'mb_decode_mimeheaders_callback', $toCharSet);
    } else {
      mb_decode_mimeheaders_callback( $value, $toCharSet);
    }
    $headers[ $name] = $value;
  }
  return $headers;
}
/**

 */
function mb_decode_mimeheaders_callback( &$value, $toCharSet) {
  $value = mb_decode_mimeheader( $value);
  if ( strstr( strtoupper( $value), "\x1B\$B")) {

    $value = mb_convert_encoding( $value, $toCharSet, 'iso-2022-jp');
  }
}
$headers = $pop3->getParsedHeaders( $msg_id);

$headers = mb_decode_mimeheaders( $headers, 'euc-jp');
/**

 */
function mail_header_date( $value) {
 return $value !='' ?

}

$muaConfig &= $config[ 'mua'];
for ( $i = $start + 1; $i <= $end; $i++) {
  $headers =
   mb_decode_mimeheaders( $pop3->getParsedHeaders( $i), $muaConfig[ 'showCharSet']);
  $subject = htmlspecialchars( mail_header_date( $headers[ 'Subject']), ' ');
  foreach ( array( 'To', 'From') as $name) {
    $$name = isset( $headers[ $name])?
     htmlspecialchars( mail_header_join( $headers[ $name], ',')): '';
  }
  $date = htmlspecialchars( mail_header_date( $headers[ 'Date']));
  print <<<EOD
<tr>
 <td><a href="$PHP_SELF?showMailIndex=$start&showMail=$i">$i</a></td>
 <td>$subject</td><td>$To</td><td>$From</td><td>$date</td>
</tr>
EOD;
}

$address->comment
$address->mailbox
$address->host

/**

 */
function exclude_mail_comment( $addressList, $defaultDomain) {
  $parsedAddress = Mail_RFC822::parseAddressList( $addressList, $defaultDomain, true);
  $newList = array();
  foreach ( $parsedAddress as $info) {
    $newList[] = "{$info->mailbox}@{$info->host}";
  }
  return implode( ',', $newList);
}

$headers = $pop3->getParsedHeaders( $msg_id);
$body = $pop3->getBody( $msg_id);
print <<<EOD
Subject: {$headers[ 'Subject']}<br>
To: {$headers[ 'To']}<br>
From: {$headers[ 'From']}<br>
<br>
$body
EOD;

$headers = $pop3->getParsedHeaders( $msg_id)

$headers( mb_decode_mimeheaders( $headers);
$Subject = htmlspecialchars( $headers[ 'Subject']);
foreach ( array( 'To', 'From') as $name) {
  $$name = isset( $headers[ $name])?
   htmlspecialchars( mail_header_join( $headers[ $name], ',')): '';
}
$body = $pop3->getBody( $msg_id);

if ( eregi( "charset=['\"]?([a-z0-9\-]+)['\"]?", $headers[ 'Content-Type'], $eregarr)) {
  $content_type = $eregarr[ 1];
  $body = mb_convert_encoding( $body, 'euc-jp', $content_type);
}
print <<<EOD
Subject: {$headers[ 'Subject']}<br>
To: {$headers[ 'To']}<br>
From: {$headers[ 'From']}<br>
<br>
$body
EOD;

global $config;
$showCharSet = $config[ 'mua'][ 'showCharSet'];
$mailCharSet = $config[ 'mua'][ 'mailCharSet']; $params['include_bodies'] = true;
$params['decode_bodies']  = false;
$params['decode_headers'] = false;
$params['input'] = $pop3->getMsg( $msg_id);
$params['crlf'] = "\r\n";

$mailObj = Mail_mimeDecode::decode( $params);

$headers = mb_decode_mimeheaders( $mailObj->headers, $showCharSet);
$subject = htmlspecialchars( $headers[ 'subject']);
foreach ( array( 'to', 'cc', 'from') as $name) {
  $$name = isset( $headers[ $name])?
   htmlspecialchars( mail_header_join( $headers[ $name], ',')): '';
}
if ( isset( $mailObj->parts)) {

  $body = '';
  $attachs = array();
  foreach ( $mailObj->parts as $index=>$parts) {
    if ( $parts->ctype_primary == 'text') {
      $charSet = $parts->ctype_parameters[ 'charset'];
      $body .= mb_convert_encoding( $parts->body, $showCharSet, $charSet);
    } else {
      $attachs[] = <<<EOD
<a href="download_attach.php?showMail=$msg_id&attach=$index" target="_new">{$parts->d_parameters[\
'filename']}</a>
EOD;
    } 
  }
  $attach = implode( ' ', $attachs);
} else {

  $contentType = $headers[ 'content-type'];
  if ( eregi( "charset=['\"]?([a-z0-9\-]+)['\"]?", $contentType, $eregarr)) {      $content_type = $eregarr[ 1];
    $body = mb_convert_encoding( $mailObj->body, 'euc-jp', $content_type);
  } else {
    $body = $mailObj->body;
  }
  $attach = '';
}
print <<<EOD

EOD;

<?php
require_once 'common.inc.php';

$pop3 = new cMyPOP3;
$pop3->connect();
$pop3->login();
$mail = isset( $_GET[ 'showMail'])? $pop3->getMsg( $_GET[ 'showMail']): '';
$pop3->disconnect();

if ( $mail != '') {

  $params['include_bodies'] = true;
  $params['decode_bodies']  = false;
  $params['decode_headers'] = true;
  $params['input'] = $mail;
  $structure = Mail_mimeDecode::decode( $params);
  if ( isset( $structure->parts[ $_GET[ 'attach']])) {

    $parts = $structure->parts[ $_GET[ 'attach']];
    $content_type = "{$parts->ctype_primary}/{$parts->ctype_secondary}";
    $name = isset( $parts->d_parameters[ 'filename'])? $parts->d_parameters[ 'filename']: '';

    header( "Content-Type: $content_type;");
    header( "Content-Disposition: filename=\"$name\"");
    switch ( strtolower( $parts->headers[ 'content-transfer-encoding'])) {

    case 'base64':
      print base64_decode( $parts->body);
      break;

    case 'print-quotable':
      print quoted_printable_decode( $parts->body);
      break;

    default:
      print $parts->body;
    }
  }  
}

<form action="create_mail.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="$uploadMaxSize">



<textarea name="body" cols="80" rows="20"></textarea><br>
<input type="file" name="attach"><br>

</form>

/**

 */
function create_message_id( $baseString) {  return sprintf( "%s.%s", md5( microtime()), $baseString);
}
/**

 */
function create_date( $time = null) {  $time = $time === null? time(): $time;
  return date( 'r', $time);
}

*1

$subject = mb_encode_mime_header( $_POST[ 'Subject']);

$attach = $_FILES[ 'attach'];
$params = array();
$params[ 'content_type'] = 'multipart/mixed';
$mimePart = new Mail_mimePart( '', $params);

$params[ "content_type"] = "text/plain; charset=$mailCharSet";
$params[ "encoding"]  = "7bit";
$mimePart->addSubPart( $body, $params);


$file = file_get_contents( $attach[ 'tmp_name']);
$params[ "content_type"] = $attach[ "type"];
$params[ "encoding"]  = "base64";
$params[ "disposition"]  = "attachment";
$params[ "dfilename"] = $attach[ "name"];
$mimePart->addSubPart( $file, $params);

$mail = $mimePart->encode();
$body = "This is a multi-part message in MIME format.\n\n{$mail[ 'body']}";
$headers = array_merge( $headers, $mail[ 'headers']);
if ( !function_extists( 'file_get_contents')) {
  function file_get_contents( $filename, $use_include_path = 0) {
    $fp = fopen( $pathname, "rb", $use_include_path);
    if ( $fp !== false) {
      return fread( $fp, filesize( $pathname));
    } else {
      return false;
    }
  }
}


*1
リロード   新規 編集 凍結 差分 添付 複製 改名   トップ 一覧 検索 最終更新 バックアップ   ヘルプ   最終更新のRSS
最終修正日時: Mon, 17 Nov 2003 13:22:06 JST (4937d)
文字数(HTML): 8652
文字数(Wiki): 13028
人気ブログランキング - よくきた wiki