Page 1 of 1

Script stopped working in 16.90.0100

Posted: 07 Jun 2016 19:21
by duarte.framos
Hey everyone
Has there been any recent changes to scripting in today's release XYPlorer 16.90.0100?

I used to run my script happily from the catalog but today after today's upgrade it stopped working. XYPlorer specifically complains about this line where I try to set a variable from a system property with

Code: Select all

$sentdate = <prop System.Message.DateSent>;
saying it is dubious sintax

Now scripting is admittedly not at all my strong suit, I am more of a copy-paster and this script is most likely anything but optimized and far from the "correct way" of doing things, but it used to work before.
Did something break unintentionally or is it my poor coding skills fault?

----
Offtopic:

It's supposed to be a script to rename Email EML files according to my preferred schema for archiving, as in
###_Year_Month_Day_SenderName_Subject
Ideally it would batch rename a selection of files but as it stands the variables are set from the first selected file only and applied to all in the selection so it doesn't work for more than one.
Also ideally they would be numbered automatically but I never figured out how to count how many EML files are already in that folder and that is probably not very trivial thing to do anyway.
If anyone care to help out it would be more then welcome.

Code: Select all

"Rename e-mail"
 if (<curext> == "eml") {

  $sentdate = <prop System.Message.DateSent>;
  $from = <prop System.Message.FromName>;
  $subject = <prop DocSubject>;

  $sentday = substr (<prop System.Message.DateSent>, 0,2);
  $sentmonth = substr (<prop System.Message.DateSent>, 3,2);
  $sentyear = substr (<prop System.Message.DateSent>, 6,4);
 
  $assembly = $sentyear._.$sentmonth._.$sentday._.$from._.$subject;

  rename b, "<#000>_"."$assembly", , , 4, "_";
  rename e, "eml";
 }
 else {
  echo "Selected file is not an email (.EML file format)";
 }

Re: Script stopped working in 16.90.0100

Posted: 07 Jun 2016 19:51
by admin
Yes, there was a change recently that is responsible for this.

Your script will work again when you quote the variable like this:

Code: Select all

$sentdate = "<prop System.Message.DateSent>";
OTOH, I would really like to keep it working without quoting... I will check that now.

Re: Script stopped working in 16.90.0100

Posted: 07 Jun 2016 20:05
by highend
A few comments:

You could replace your if / else construct with but ofc this only works for a single file check:

Code: Select all

end <curext> != "eml", "Selected file is not an email (.EML file format)";
Why are you defining $sentdate when you never use it?

Please don't concatenate strings that aren't quoted

Code: Select all

$assembly = $sentyear.'_'.$sentmonth.'_'.$sentday.'_'.$from.'_'.$subject;

Re: Script stopped working in 16.90.0100

Posted: 07 Jun 2016 20:16
by admin
admin wrote:OTOH, I would really like to keep it working without quoting... I will check that now.
Looks like I could manage to do this. Check out the next beta.

EDIT: well, not really, not fully. So quoting is definitely recommended!

Re: Script stopped working in 16.90.0100

Posted: 07 Jun 2016 20:24
by highend
How a script could look like that works on multiple .eml files at once. Just execute the script when you are in the folder that contains these files...

Code: Select all

"Rename e-mail"
    setting "BackgroundFileOps", 0;
    $emlFiles = listfolder(<curpath>, "*.eml", 4);
    while ($i++ < gettoken($emlFiles, "count", "|")) {
        $emlFile = gettoken($emlFiles, $i, "|");
        $from = property("System.Message.FromName", $emlFile);
        $subject = property("DocSubject", $emlFile);

        $sentDate = formatdate(property("System.Message.DateSent", $emlFile), "_yyyy_mm_dd_");
        $assembly = format($i, "000") . $sentDate . $from . "_" . $subject;
        rename "b", $assembly, , "<curpath>\$emlFile", 4;
    }

Re: Script stopped working in 16.90.0100

Posted: 07 Jun 2016 21:19
by PeterH
admin wrote:
admin wrote:OTOH, I would really like to keep it working without quoting... I will check that now.
Looks like I could manage to do this. Check out the next beta.

EDIT: well, not really, not fully. So quoting is definitely recommended!
:shock: Hm - a variable that must be quoted. To me this really looks a bit strange. :?

Re: Script stopped working in 16.90.0100

Posted: 07 Jun 2016 21:25
by highend
Isn't quoting the property enough?

Code: Select all

<prop "System.Message.FromName">;

Re: Script stopped working in 16.90.0100

Posted: 07 Jun 2016 21:31
by admin
Yes, it's enough.

Re: Script stopped working in 16.90.0100

Posted: 07 Jun 2016 21:44
by duarte.framos
highend wrote:You could replace your if / else construct with but ofc this only works for a single file check:
Why are you defining $sentdate when you never use it?
Please don't concatenate strings that aren't quoted
Ah yes, my clear lack of skills is clearly showing here, much cleaner solution without the if, and yes that $sentdate was a leftover from my experiments. How clumsy of me.
admin wrote:
admin wrote:OTOH, I would really like to keep it working without quoting... I will check that now.
EDIT: well, not really, not fully. So quoting is definitely recommended!
Yes it works well know. I am quite ok with the required quoting, I was just not smart enough to figure it out on my own.
I always read the release notes looking for features and changes and since this release only stated 'minor bug fixes' I was not expecting the scripts to break
Anyway, quoting variables solves the problem quite well, now working as expected.

Many thanks for the quick replies and all the help.
In the process I've already learnt a few things with this :mrgreen:

Re: Script stopped working in 16.90.0100

Posted: 07 Jun 2016 21:46
by admin
Well ... :oops: ... in theory nothing should break user scripts, neither major nor minor upgrades. But in this case the old state was close to a bug so it needed to be changed. Reality 1, theory 0.

Re: Script stopped working in 16.90.0100

Posted: 07 Jun 2016 21:52
by duarte.framos
highend wrote:How a script could look like that works on multiple .eml files at once. Just execute the script when you are in the folder that contains these files...

Code: Select all

"Rename e-mail"
    setting "BackgroundFileOps", 0;
    $emlFiles = listfolder(<curpath>, "*.eml", 4);
    while ($i++ < gettoken($emlFiles, "count", "|")) {
        $emlFile = gettoken($emlFiles, $i, "|");
        $from = property("System.Message.FromName", $emlFile);
        $subject = property("DocSubject", $emlFile);

        $sentDate = formatdate(property("System.Message.DateSent", $emlFile), "_yyyy_mm_dd_");
        $assembly = format($i, "000") . $sentDate . $from . "_" . $subject;
        rename "b", $assembly, , "<curpath>\$emlFile", 4;
    }
This works perfectly, many many thanks for your valuable input; this is what I would have done if I had the required skills, which clearly I don't eheh
With it I already found errors in some larger mail archives from other projects, obviously my manual numbering introduced a few human errors :roll:
I will now analyze it carefully and try to learn something from it, a lot of the wizardry you used is way over my head. :biggrin:

Again thanks for all the help and quick input, script safely added to my library.

Re: Script stopped working in 16.90.0100

Posted: 07 Jun 2016 23:27
by duarte.framos
admin wrote:Well ... :oops: ... in theory nothing should break user scripts, neither major nor minor upgrades. But in this case the old state was close to a bug so it needed to be changed. Reality 1, theory 0.
Well apparently my scripts were really about to cross the line and asking for it, so they are probably a little less bad now and I just learned how to properly quote my variables, so I guess overall it was still an improvement in all fronts :tup: