PHP_FE(imap_search, NULL)
PHP_FE(imap_utf7_decode, NULL)
PHP_FE(imap_utf7_encode, NULL)
+ PHP_FE(imap_utf8, NULL)
{NULL, NULL, NULL}
};
int myargc=ARG_COUNT(ht);
if (myargc < 2 || myargc > 3 || getParameters(ht,myargc,&streamind,&sequence,&flags) == FAILURE) {
- WRONG_PARAM_COUNT;
+ WRONG_PARAM_COUNT;
}
convert_to_long(streamind);
convert_to_string(sequence);
+ if(myargc==3) convert_to_long(flags);
ind = streamind->value.lval;
pval *arg;
const unsigned char *in, *inp, *endp;
unsigned char *out, *outp;
- int inlen, outlen;
+ int inlen, outlen, slen;
enum { ST_NORMAL, /* printable text */
ST_ENCODE0, /* encoded text rotation... */
ST_ENCODE1,
while (inp < endp) {
if (state == ST_NORMAL) {
if (SPECIAL(*inp)) {
- state = ST_ENCODE0;
- outlen++;
+ state = ST_ENCODE1;
+ slen=1;
}
- else if (*inp++ == '&') {
+ else if (*inp == '&') {
outlen++;
}
outlen++;
}
else if (!SPECIAL(*inp)) {
state = ST_NORMAL;
+ outlen+=2+slen*3-slen/3;
+ slen=0;
}
else {
- /* ST_ENCODE0 -> ST_ENCODE1 - two chars
- * ST_ENCODE1 -> ST_ENCODE2 - one char
- * ST_ENCODE2 -> ST_ENCODE0 - one char
- */
- if (state == ST_ENCODE2) {
- state = ST_ENCODE0;
- }
- else if (state++ == ST_ENCODE0) {
- outlen++;
- }
- outlen++;
- inp++;
+ slen++;
}
+ inp++;
}
+ if(state!=ST_NORMAL)
+ outlen+=1+slen*3-slen/3;
/* allocate output buffer */
if ((out = emalloc(outlen + 1)) == NULL) {
/* encode input character */
switch (state) {
case ST_ENCODE0:
- *outp++ = B64(*inp >> 2);
- *outp = *inp++ << 4;
+ *outp++ = B64((*inp>>8) >> 2);
+ *outp = (*inp>>8) << 4;
+ state = ST_ENCODE1;
+ break;
+ case ST_ENCODE1:
+ *outp++ = B64(*outp | (*inp>>8) >> 4);
+ *outp = (*inp>>8) << 2;
+ state = ST_ENCODE2;
+ break;
+ case ST_ENCODE2:
+ *outp++ = B64(*outp | (*inp>>8) >> 6);
+ *outp++ = B64((*inp>>8));
+ state = ST_ENCODE0;
+ case ST_NORMAL:
+ break;
+ }
+ switch (state) {
+ case ST_ENCODE0:
+ *outp++ = B64((*inp&0xff) >> 2);
+ *outp = (*inp&0xff) << 4;
state = ST_ENCODE1;
break;
case ST_ENCODE1:
- *outp++ = B64(*outp | *inp >> 4);
- *outp = *inp++ << 2;
+ *outp++ = B64(*outp | (*inp&0xff) >> 4);
+ *outp = (*inp&0xff) << 2;
state = ST_ENCODE2;
break;
case ST_ENCODE2:
- *outp++ = B64(*outp | *inp >> 6);
- *outp++ = B64(*inp++);
+ *outp++ = B64(*outp | (*inp&0xff) >> 6);
+ *outp++ = B64((*inp&0xff));
state = ST_ENCODE0;
case ST_NORMAL:
break;
}
+ inp++;
}
}
Read an overview of the information in the headers of the given message */
PHP_FUNCTION(imap_fetch_overview)
{
- pval *streamind, *sequence;
+ pval *streamind, *sequence, *flags;
int ind, ind_type;
pils *imap_le_struct;
pval *myoverview;
char address[MAILTMPLEN];
int myargc=ARG_COUNT(ht);
+ long status,flags=0L;
- if (myargc != 2 || getParameters(ht,myargc,&streamind,&sequence) == FAILURE) {
+ if (myargc <2 || myargc >3 || getParameters(ht,myargc,&streamind,&sequence,&flags) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(streamind);
convert_to_string(sequence);
-
+ if(myargc==3) {
+ convert_to_long(pflags);
+ flags = pflags->value.lval;
+ }
ind = streamind->value.lval;
imap_le_struct = (pils *)zend_list_find(ind, &ind_type);
RETURN_FALSE;
}
array_init(return_value);
- if (mail_uid_sequence (imap_le_struct->imap_stream,(char *)sequence)) {
+
+ status = (flags & FT_UID)
+ ? mail_uid_sequence (imap_le_struct->imap_stream,sequence->value.str.val)
+ : mail_sequence (imap_le_struct->imap_stream,sequence->value.str.val)
+ ;
+
+
+ if (status) {
MESSAGECACHE *elt;
ENVELOPE *env;
unsigned long i;
(env = mail_fetch_structure (imap_le_struct->imap_stream,i,NIL,NIL))) {
MAKE_STD_ZVAL(myoverview);
object_init(myoverview);
- add_property_string(myoverview,"subject",env->subject,1);
- env->from->next=NULL;
- rfc822_write_address(address,env->from);
- add_property_string(myoverview,"from",address,1);
- add_property_string(myoverview,"date",env->date,1);
- add_property_string(myoverview,"message_id",env->message_id,1);
- add_property_string(myoverview,"references",env->references,1);
+ if(env->subject)
+ add_property_string(myoverview,"subject",env->subject,1);
+ if(env->from) {
+ env->from->next=NULL;
+ rfc822_write_address(address,env->from);
+ add_property_string(myoverview,"from",address,1);
+ }
+ if(env->date)
+ add_property_string(myoverview,"date",env->date,1);
+ if(env->message_id)
+ add_property_string(myoverview,"message_id",env->message_id,1);
+ if(env->references)
+ add_property_string(myoverview,"references",env->references,1);
add_property_long(myoverview,"size",elt->rfc822_size);
add_property_long(myoverview,"uid",mail_uid(imap_le_struct->imap_stream,i));
add_property_long(myoverview,"msgno",i);
}
sendmail = popen(INI_STR("sendmail_path"), "w");
if (sendmail) {
+ if (rpath && rpath[0]) fprintf(sendmail, "From: %s\n", rpath);
fprintf(sendmail, "To: %s\n", to);
if (cc && cc[0]) fprintf(sendmail, "Cc: %s\n", cc);
if (bcc && bcc[0]) fprintf(sendmail, "Bcc: %s\n", bcc);
static void php_stat(const char *filename, int type, pval *return_value)
{
struct stat *stat_sb;
+ int rmask=S_IROTH,wmask=S_IWOTH,xmask=S_IXOTH; /* access rights defaults to other */
BLS_FETCH();
stat_sb = &BG(sb);
}
#endif
+
+ if(BG(sb).st_uid==getuid()) {
+ rmask=S_IRUSR;
+ wmask=S_IWUSR;
+ xmask=S_IXUSR;
+ } else if(BG(sb).st_gid==getgid()) {
+ rmask=S_IRGRP;
+ wmask=S_IWGRP;
+ xmask=S_IXGRP;
+ } else {
+ int groups,n,i;
+ gid_t *gids;
+
+ groups = getgroups(0,NULL);
+ if(groups) {
+ gids=(gid_t *)emalloc(groups*sizeof(gid_t));
+ n=getgroups(groups,gids);
+ for(i=0;i<n;i++){
+ if(BG(sb).st_gid==gids[i]) {
+ rmask=S_IRGRP;
+ wmask=S_IWGRP;
+ xmask=S_IXGRP;
+ break;
+ }
+ }
+ efree(gids);
+ }
+ }
+
switch(type) {
case 0: /* fileperms */
RETURN_LONG((long)BG(sb).st_mode);
php_error(E_WARNING,"Unknown file type (%d)",BG(sb).st_mode&S_IFMT);
RETURN_STRING("unknown",1);
case 9: /*is writable*/
- RETURN_LONG((BG(sb).st_mode&S_IWRITE)!=0);
+ if(getuid()==0) RETURN_LONG(1); /* root */
+ RETURN_LONG((BG(sb).st_mode&wmask)!=0);
case 10: /*is readable*/
- RETURN_LONG((BG(sb).st_mode&S_IREAD)!=0);
+ if(getuid()==0) RETURN_LONG(1); /* root */
+ RETURN_LONG((BG(sb).st_mode&rmask)!=0);
case 11: /*is executable*/
- RETURN_LONG((BG(sb).st_mode&S_IEXEC)!=0 && !S_ISDIR(BG(sb).st_mode));
+ if(getuid()==0) RETURN_LONG(1); /* root */
+ RETURN_LONG((BG(sb).st_mode&xmask)!=0 && !S_ISDIR(BG(sb).st_mode));
case 12: /*is file*/
RETURN_LONG(S_ISREG(BG(sb).st_mode));
case 13: /*is dir*/