mIRC Homepage
Posted By: Perl convert base64 to jpg? - 18/05/15 02:27 AM
Hello, I would like to convert an encoded base64 I've read email, to its original format jpg file.
by socket I read this;

R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZ
u6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABA
AAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGI
gUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7

Is it possible to convert base64 encoded in a file photo.jpg to do with any photo viewer? greetings
Posted By: Loki12583 Re: convert base64 to jpg? - 18/05/15 11:58 AM
Code:
alias saveb64 {
  bset -t &b 1 $1
  var %file = $qt($$2-)
  if ($decode(&b,mb)) {
    bwrite %file -1 -1 &b
  }
}
Posted By: Perl Re: convert base64 to jpg? - 18/05/15 12:21 PM
Originally Posted By: Loki12583
Code:
alias saveb64 {
  var %file = $qt($1)
  bset -t &b 1 $$2-
  if ($decode(&b,mb)) {
    bwrite %file -1 -1 &b
  }
}


Thanks for answering, but I get it to work, as it would be used? I put filename origin and destination and would not generate anything you could put me as it used?

The purpose of this is to download an attached photo of an electronic mail, I wonder if this method also would be another possible, but as much as I read in the forum can not find it, use POP3 protocol to read email. regards
Posted By: Loki12583 Re: convert base64 to jpg? - 18/05/15 12:44 PM
I flipped the arguments around because the base64 should not have spaces and the filename can, so the filename should come second.

Call /saveb64 %text %file
Posted By: Perl Re: convert base64 to jpg? - 18/05/15 02:05 PM
Originally Posted By: Loki12583
I flipped the arguments around because the base64 should not have spaces and the filename can, so the filename should come second.

Call /saveb64 %text %file


thank iu Loki12583 ,
works very well with short lines, long lines to get in mIRC gives me error and not recomposed me photo, you can not view it, how you could do with those lines? because attempts to put in a variable line tells me too long and if I try to write it in a file tells me the same thing, but I'm testing to see if you can get it all on one line, is there any other option?
Posted By: Loki12583 Re: convert base64 to jpg? - 18/05/15 03:39 PM
mIRC has a line length limit, use whatever means necessary to get the base64 text into a file and then you can use these aliases to read from that file and decode into a new file:

Code:
alias file.base64.decode.save {
  var %source = $qt($1), %destination = $qt($2)
  if ($file.base64.decode(%source)) {
    bwrite %destination -1 -1 $v1
  }
}

alias file.base64.decode {
  var %file = $qt($1), %bvar = $iif(&* iswm $2,$2,&b)
  bread $qt(%file) 0 $file(%file).size %bvar
  if ($decode(%bvar,mb)) {
    if ($prop == text) return $bvar(%bvar,1-).text
    else return %bvar
  }
}


If the line is too wrong for you to read it from a text sockread you need to binary variables; you can ask specific questions but I'm not going to explain the general workings of binary variables and sockets in a forum post when the help files and many online tutorials have done that already.
Posted By: Perl Re: convert base64 to jpg? - 18/05/15 04:05 PM
Originally Posted By: Loki12583
mIRC has a line length limit, use whatever means necessary to get the base64 text into a file and then you can use these aliases to read from that file and decode into a new file:

Code:
alias file.base64.decode.save {
  var %source = $qt($1), %destination = $qt($2)
  if ($file.base64.decode(%source)) {
    bwrite %destination -1 -1 $v1
  }
}

alias file.base64.decode {
  var %file = $qt($1), %bvar = $iif(&* iswm $2,$2,&b)
  bread $qt(%file) 0 $file(%file).size %bvar
  if ($decode(%bvar,mb)) {
    if ($prop == text) return $bvar(%bvar,1-).text
    else return %bvar
  }
}


If the line is too wrong for you to read it from a text sockread you need to binary variables; you can ask specific questions but I'm not going to explain the general workings of binary variables and sockets in a forum post when the help files and many online tutorials have done that already.


thanks, will study the binary variables when you have some time, but that alias file.base64.decode.save gives me a defective picture, instead of leaving a file with star-shaped leaves a square of the same color orange, not if that I'm not wearing well, just I do this:
Code:
/file.base64.decode.save $mircscript $+ source.txt $mircscript $+ photo.jpg


Regards
© mIRC Discussion Forums