# Copyright (c) 2006-2008 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: MailSubject.pm,v 1.3 2008/02/11 04:48:41 nagler Exp $ package Bivio::Type::MailSubject; use strict; use base 'Bivio::Type::Line'; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.3 $ =~ /\d+/g); sub CLEAN_REGEX { return qr{\s$|/|@{[shift->get_instance('FilePath')->ILLEGAL_CHAR_REGEXP]}}o; } sub EMPTY_VALUE { return '(No Subject)'; } sub clean_and_trim { return lc(shift->trim_literal($_[0], 1)); } sub trim_literal { my($proto, $value, $clean) = @_; $value = '' unless defined($value); $value =~ s/\s+/ /; 0 while $value =~ s/^(\s+|\[\S*\]|[a-z]{1,3}(:|\[\d+\])|\.)//i; $value =~ s{@{[$proto->CLEAN_REGEX]}}{}g if $clean; return length($value) ? substr($value, 0, $proto->get_width) : $proto->EMPTY_VALUE; } 1;