Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Convert all email printing to grayscale
- *
- * Implement an organization wide policy that no emails should be printed in
- * color. Often emails contain color in links or headers that adds no value.
- * This script automatically converts all emails (printed from Outlook) to
- * grayscale.
- */
- function printJobHook(inputs, actions) {
- /*
- * Set this to the unique text that appears in the print queue when emails are
- * printed by your organization's email client. This script will work with
- * email applications that use a specific identifiable string in the job
- * title. If the application only uses the email title for instance then this
- * approach will not work.
- */
- if (!inputs.job.isAnalysisComplete) {
- // Full job details are not yet available. Return and wait to be called again.
- return;
- }
- var EMAIL_APPLICATION_TITLES = [ 'Microsoft Outlook', 'Microsoft Office Outlook', 'outbind://' ];
- var CONVERT_MESSAGE = 'Your job contains colour pages. Would you like to convert your job to grayscale? Selecting "No" will print the job in colour, Selecting "YES" will change the job to greyscale.';
- // See if the document name matches any of the known email titles
- if ((inputs.job.isColor) && (matchesAny(inputs.job.documentName, EMAIL_APPLICATION_TITLES))) {
- // This job is an email, convert it to grayscale
- actions.job.convertToGrayscale();
- // If the user is running the client tool we'll send them a courtesy message
- // If they are not, no problems
- if (inputs.client.isRunning) {
- actions.client.sendMessage('Your email has been automatically converted to grayscale.');
- }
- }
- if ((inputs.job.isColor) && (!matchesAny(inputs.job.documentName, EMAIL_APPLICATION_TITLES))) {
- // Color job and not an email, ask the use if they want to print.
- if (inputs.client.isRunning) {
- // User is running the client software. Ask if they want to convert to grayscale or cancel.
- var response = actions.client.promptYesNo(CONVERT_MESSAGE);
- if (response == 'NO') {
- // User chose to print in color.
- actions.log.debug('User chose to keep on printing in color');
- } else if (response == 'TIMEOUT') {
- // Client timed out, cancel the job.
- actions.log.debug('Dialog timed out, canceling job.');
- actions.job.cancel();
- } else {
- // User chose to convert the job - good work user!
- actions.log.debug('User chose to convert their job to grayscale.');
- actions.job.convertToGrayscale();
- }
- } else {
- // User is not running the client software, so cancel the job.
- actions.log.debug('User not running client software.');
- actions.job.cancel();
- }
- }
- // Job is Grayscale and not an email, so we will let the job through.
- }
- function matchesAny(str, matchStrs, actions) {
- if (str == null || matchStrs == null) {
- return false;
- }
- for ( var i in matchStrs) {
- if (str.match(matchStrs[i])) {
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment